#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
Pingback: Dew Drop – May 24, 2013 (#1,554) | Alvin Ashcraft's Morning Dew
This is a great post. Few implement it correctly though, especially when creating custom exceptions. I found this great article on creating custom exceptions. Take a look: http://blogs.msdn.com/b/agileer/archive/2013/05/17/the-right-way-to-write-a-custom-exception-class.aspx
Pingback: #884 – Things You Might Do in an Exception Handler | 2,000 Things You Should Know About C#