Sunday, 23 December 2012 13:54

c# exception handling

Written by 
Rate this item
(0 votes)

It's a good idea to identify the errors at run time to detect
and handle it. .Net framework has built in mechanism for that.
these exceptions occurs because of user,logic and system errors.

.NET run time environment supplies a default mechanism(ter-
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.

Read 1629 times
Super User

Email This email address is being protected from spambots. You need JavaScript enabled to view it.
Login to post comments