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