Exception Handling

Exception Handling

Whenever you write a code, there is a chance that things will not come out as you have been expecting, which results in that the code does not compile, or crash, or otherwise unexpected behavior of your application.

An error can occur due to the number of reasons as when you misspelling a word or text in your code or the database server you are connecting to at run time suddenly goes down or you got your logic mixed up and accidentally deleted all rows from a database table or you try to delete a row from a database table that still has associated row or you try to write a file to a folder without proper permissions or you enter incorrect data, and so on.

To understand these problems and to avoid, and handle them, you first need to understand the different types of errors that may occur in your website. Most .NET languages support structured exception handling.

Structured exception handling provides several key features:

Exceptions are object based: Each exception provides you a sufficient amount of important information wrapped into an accurate object, instead of a simple message and error code. These exceptions objects also support an InnerException property that allows you to wrap a general error over the more specific error that caused it. You can even create and throw your own exception objects.
Exceptions are caught based on their type: This allows you to well organized error-handling code without needing to sift through obscure error codes.
Exception handlers use a modern block structure: It makes easy to activate and deactivate different error handlers for different sections of code and handle their errors individually.
Exception handlers are multilayered: You can easily layer exception handlers on top of other exception handlers, some of which may check for only a specialized set of errors.
Exceptions are a general part of the .NET framework: This means they are completely cross-language compatible.

Exception Handlers are a key programming technique,which allows you to react to the problems that occur at runtime.

Scroll to Top