#851 – A General Philosophy for Handling Exceptions
May 24, 2013 3 Comments
An exception is an event that occurs at run-time and is not part of the normal expected execution of your code. Exceptions can arise because of user errors, runtime errors, or bugs in your application.
You can include code in your application to catch and handle exceptions. Your exception handling code will intercept exceptions that occur and you will then have a chance to react to the exception that is occurring.
As a general guideline for handling exceptions, you should:
- Handle any exceptions that you can do something about.
- E.g. Catch exceptions that indicate that the user entered malformed input and inform the user of what went wrong.
- Include a top-level handler for unhandled exceptions
- In this handler, inform the user that an unrecoverable error occurred.
- Optionally, log information about the exception, to help diagnose what went wrong