minates the execution of program),if the programmer does not
provides a technique for handling these exceptions.
c# has 3 keywords try,catch and finally for exception handling.
the try encloses the expressions that might give an exception,but
catch block handles those exceptions.finally keyword is used to
do clean up.following codes shows the syntax form of try-catch-
finally mechanism-
try
{ // Statements may cause an exception. }
catch(Type x)
{ // Statements for handling the exception }
finally
{ //cleanup codes }
if exception occurs in the try block,then the control is
transferred to the proper catch block and then to
finally block.
if there is no exception generated in the try block,then control
directly goes to the finally block.so finally block statements
always executed.
in c# programming language exceptions are objects of Exception
type.Exception is the base class for any types of exceptions in
c#.c# also provides many standard exceptions.even the programmers
can generate their exception classes.