#884 – Things You Might Do in an Exception Handler
July 10, 2013 1 Comment
You should typically only handle exceptions that you can do something about and where the cause of the exception is fully understood.
If you can fully recover from an exception, you might catch the exception and then report the problem to the user. This makes sense if the user can do something differently to prevent the exception. For example, you might:
- Report invalid inputs and ask the user to enter valid data
- Report IO failures due to a disk being full
- Report IO failures due to the user not having the required permissions
- Report that the user’s login credentials did not work
- Retry an operation
In other cases, you might do something in response to an exception within a handler and then rethrow the exception. You might:
- Log the exception
- Send an e-mail
- Inform the user about an unrecoverable error