17.1. Exception Handling
Whenever you write code, there is a chance things won't turn out as expected, resulting in non-compatible code, a crash, or otherwise unexpected behavior of your application. Things can go wrong for a large number of reasons: you introduced a typo in your code, the database server you're connecting to at run time suddenly goes down, you got your logic mixed up and accidentally deleted all records from a database table instead of just one, you try to delete a record from a database table that still has associated records, you try to write a file to a folder without proper permissions, your users enter incorrect data, and so forth.
In order to understand these problems and think of ways to anticipate, avoid, and handle them, you first need to understand the different types of errors that may occur in your web application. Once you understand the main differences, the remainder of this section is spent discussing ways to prevent and solve them.
17.1.1. Different Types of Errors
You can broadly categorize errors into the following groups:
Syntax errors: Errors that are caused by typos or missing keywords, for example.
Logic errors: Errors in applications that seem to run fine but that produce unexpected or unwanted results.
Run-time errors: Errors that cause the application to crash or behave unexpectedly at run time.
Each of these categories is discussed in the following sections, together with information on avoiding and fixing them.
17.1.1.1. Syntax Errors ...
Get Beginning ASP.NET 3.5: In C# and VB now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.