Slideshare uses cookies to improve functionality and performance, and to provide you with relevant advertising. If you continue browsing the site, you agree to the use of cookies on this website. See our User Agreement and Privacy Policy.

Slideshare uses cookies to improve functionality and performance, and to provide you with relevant advertising. If you continue browsing the site, you agree to the use of cookies on this website. See our Privacy Policy and User Agreement for details.

7.
Describe Exception
An exception is an erroneous situation that occurs during
program execution.
When an exception occurs in an application, the system
throws an error.
The error is handled through the process of exception
handling.

8.
Types of Error
There are three types of errors that can occur in the application:
Syntax errors: Occurs when statements are not constructed
properly, keywords are misspelled, or punctuation is omitted.
Run-time errors: Occurs when an application attempts to perform
an operation, which is not allowed at runtime.
Logical errors: Occurs when an application compiles and runs
properly but does not produce the expected results.
Let us understand the various types of errors in detail.

12.
There are many exception classes which are
directly or indirectly derived from the
System.Exception class. Some of these
classes are:
System.ApplicationException class
System.SystemException class
Exception Classes

13.
—The hierarchy of the exception classes is displayed in the following
figure.
Exception Classes
System. Exception
System.ApplicationException
System.SystemException

14.
Handling Exception
In exception handling, the application is divided into blocks of code.
A block that shows the probability of raising an error contains one or
more exception handlers.
The exception handlers follow a control structure and a uniform way of
handling the system level and application level errors.
The blocks for exception-handling can be implemented using the
following keywords:
try
catch
finally
Let us look at each of these keywords in detail.

16.
Try Block
The try block:
The try block guards statements that may throw an exception. Following is
the syntax of try block statement:
try
{
//statements that may cause an exception
}
The try block governs statements that are enclosed within it and defines
the scope of the exception-handlers associated with it.
A try block must have at least one catch block.

17.
Catch Block
The catch block:
The catch statement of the catch block takes an object of the exception
class as a parameter, which refers to the raised exception.
You can associate an exception-handler with the try block by providing
one or more catch handlers, immediately after the try block:
try
{
//statements that may cause an exception
}
catch (…)
{
//error handling code
}

18.
Finally Block
The finally block:
The finally block is used to execute a given set of
statements, whether an exception is thrown or not thrown:
try
{
//statements that may cause an exception
}
catch (…)
{
//error handling code
}
finally
{
//statements to be executed
}