Professional Documents
Culture Documents
Chapter 4
Chapter 4
Exception Handling
A reference of MSDN Library for Visual Studio 2017
Exception Class
Try statement
Example
Slide 2
Introduction
An exception is any error condition or
Chapter 4. Exception Handling
Slide 3
Introduction
In the .NET Framework, an exception is an
Chapter 4. Exception Handling
Slide 4
Exception Class
The Exception class is the base class from
Chapter 4. Exception Handling
Slide 5
Exception Class
Common Properties
Chapter 4. Exception Handling
Message: Provides details about the cause of an
exception.
StackTrace: Contains a stack trace that can be
used to determine where an error occurred. The
stack trace includes the source file name and
program line number if debugging information is
available.
Slide 6
Try statement
A common usage of catch and finally
Chapter 4. Exception Handling
Slide 7
try statement
try ...catch ... finally Statement
Chapter 4. Exception Handling
try
{
1. Include codes in which exceptions might occur.
}
catch (Exception )
{
2. Represent types of exceptions the catch can handle.
}
finally
{
3.(Optional) codes present here will always execute.
}
Slide 8
Example
Example: Divide by zero
Chapter 4. Exception Handling
Slide 9
Example
Code pattern
Chapter 4. Exception Handling