Summary
Exception handling provides a way to deal with unusual occurrences in your program. Each of the different exception-handling techniques provides a way to set aside the complexity of dealing with these unusual occurrences so that they do not obscure the main logic of your application.
Exception-handling structures use the Try, Catch, Finally (Visual Basic .NET) or try, catch, finally (Visual C#) keywords to handle exceptions within a procedure.
Catch exceptions in order from most the most specific exception type to the most general exception type.
Use the Throw (Visual Basic .NET) or throw (Visual C#) keyword to intentionally cause an exception.
Error events handle exceptions in a separate event procedure. Use the Server object s GetLastError and ClearError methods to handle exceptions within error events.
Use error pages to handle exceptions that occur outside of Web application code or as a backstop for presenting user-friendly error messages for unhandled errors in code.
Monitor exceptions that are handled in your application by writing messages to the trace log using the Trace object s Write and Warn methods.
Enable application-level tracing by setting the <trace> element s attributes in the Web.config file.
Enable page-level tracing by setting the Trace attribute in a Web form s @ Page directive.