Exception handling

Answer Posted / alb.shah

"An exception handler is a piece of code which will be
called when an exception occurs."

.NET Framework provides several classes to work with
exceptions. The keywords try, catch are used to handle
exceptions in .NET. You have to put the code (that can
cause an exception) in a try block. If an exception occurs
at any line of code inside a try block, the control of
execution will be transfered to the code inside the catch
block.
If any statement within the try block raises an exception,
the control of execution will be transfered to the first
line within the catch block. You can write the error
handling code in the catch block, like recording the error
message into a log file, sending an email to the
administrator about the problem occurred, showing an
appropriate error message to the user etc.
You can optionally use a 'finally' block along with the try-
catch. The 'finally' block is guaranteed to be executed
even if there is an exception.
If an exception is not 'handled' in code, the application
will crash and user will see an ugly message. Instead, you
can catch the exception, log the errors and show a friendly
message to the user.

Is This Answer Correct ?    2 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What are the advantages and limitations of query string?

574


Explain the reason why the javascript validation not run on the asp.net button but run successfully on the html button?

578


What websites use asp.net?

526


What is difference between cache and session?

502


Why session is used in asp.net?

533






What are the asp.net security controls?

558


If you are using two select queries and retrieving data. how do you access second query's result set using data reader?

4756


How to set the pane area to transparent of a scrollPane component.?

570


What is the usage of DelegatingHandler?

593


What are the asp.net list controls and difference between them?

520


What is autopostback true?

613


They mostly asked difference between versions of technologies

957


What is web api vs wcf?

583


What is the extension of master page in asp.net?

552


What is semantic gap?

626