Chapter 4 — Exceptions

SAMS CSHARP 4.0 (Page 80)

Throw an Exception

Catch an Exception

using try… catch….

Catch Multiple Exceptions

You must andle many potential exceptions

Execution with finally

Code in finally will guaranteed to run after try/catch.

Exception: If you use Environment.Exit(),
then the finally will not be executed.

Get Useful Information from an Exception

Message – a brief of the error
Source – the application where the exception occurred
StackTrace – a list of the methods in the current stack. Helpful to retrace the path that caused the exception
targetSite – the method that threw the exception
innerException – exception that caused the current exception. Often, exceptions are wrapped inside other higher-level exceptions.
Data – Exception-specific pairs providing more info

Catch Unhandled Exceptions

Create a custom handler for all exceptions not caught by try/catch….

A thrown exception is passed up the call stack until it finds a catch block that can handle it. If no handler, the process will be shut down.

Trapping ASP.NET app’s exception at an application level: change global.asax, in the Application_Error method.

Advertisements
Post a comment or leave a trackback: Trackback URL.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: