You are on page 1of 1

Exceptions & Exception Handling:

-Generally under every program we will be comming across errors which are of 2
types:
-Compile Time Errors
-Run Time Errors

-A compile time error occurs due to the syntactical mistake that occurs in a
program, these are not considered to be dangerous.

-A runtime error also known as an Exception occurs under a program while the
execution of the program is taking place this can be due to various reasons like
wrong implementation of logic, invalid input supplied to the program etc., these
errors are considered to be dangerous because when they occur under the program the
program terminates abnormally with out executing the next lines of code.

-What happens when an exception or runtime error occurs under a program ?


Ans: When ever an exception occurs in a program on a certain line, the execution of
the program stops immediately on the line with out executing the next lines of code
as well as displays an error msg related with the error.

-What is an Exception as a programmer ?


Ans: As a programmer every exception is a class which is defined under the system
namaspace. The parent class for all these exeception classes is "Exception".

-How can we stop the abnormal termination that occurs when an exception occurs ?
Ans: To stop the abnormal termination that occurs when an exception occurs we are
provided with an approach known as "Exception Handling", which allows u to stop the
abnormal termination as well as can be used to display user friendly error msgs to
the end users.

-How to perform Exception Handling within a program ?


Ans: To perform Exception Handling we were provided with 2 blocks of code known as
"try..catch" blocks, which has to be used as following:

try
{
-Stmts which will cause the exception
-Stmts which are related with the exception and should not execute when
exception occurs
}
catch (<exception> <var>)
{
-Stmts which should execute only when the exception occurs
}
-----<multiple catch blocks>.....

You might also like