You need to sign in to do that
Don't have an account?

Error Handling Best Practice?
I'm new to Apex and have a very general question:
* Should I put Try..Catch..Finally statements in ALL of my class methods? Or,
* Should I only add the Try..Catch..Finally to the main method and not add any handling on the subroutines?
What's the best practice?
* Should I put Try..Catch..Finally statements in ALL of my class methods? Or,
* Should I only add the Try..Catch..Finally to the main method and not add any handling on the subroutines?
What's the best practice?
A widely used best-practice is to "Throw Early Catch Late", which roughly translates to that you should try catch exceptions as late as possible, mostly to user-invoked or primary action methods.
Here is an interesting article, look at Exception Handling Best Practices section. This is based on Java, but does explain some principles and best practices:
http://www.journaldev.com/1696/java-exception-handling-tutorial-with-examples-and-best-practices
All Answers
There is no best practice with respect to Try--Catch--Finally statements.
It is not a good advice to put try--catch in all your class methods as each try catch block takes more time to execute. Encapsulate your logic (whereever needed) in try-catch if you expect that that block would throw runtime errors.
A widely used best-practice is to "Throw Early Catch Late", which roughly translates to that you should try catch exceptions as late as possible, mostly to user-invoked or primary action methods.
Here is an interesting article, look at Exception Handling Best Practices section. This is based on Java, but does explain some principles and best practices:
http://www.journaldev.com/1696/java-exception-handling-tutorial-with-examples-and-best-practices