Question - Define Exception handling in ASP.NET.
Answer - Exceptions or errors are
unusual occurrences that happen within the logic of an application. The CLR has
provided structured way to deal with exceptions using Try/Catch block. ASP.NET
also supports exception handling through server events such as
Page_Error and Application_Error events.
Question - What are the ways of handling
exceptions in ASP.NET?
Answer - There are three ways to
handle exceptions in ASP.NET
Try/catch/finally block.
Using Events like Page_Error and Application_Error
Using Custom error page
Question - Explain Try/catch block of exception
handling.
Answer -
You can enclose code in Try/Catch/Finally block. You can catch all exceptions
in the catch block. The third part of this block is finally. It is executed
irrespective of the fact that an exception has been raised.
Question - Define Error Events.
Answer - ASP.NET supports events that
occur when any unhandled exception occurs in an application. These events
are called as Error Events.
ASP.NET provides two such events to handle exceptions
-
Page_Error : This is page event and is raised when any
unhandled exception occur in the page.
-
Application_Error: This is application event and is raised
for all unhandled exceptions in the ASP.NET application and is implemented in
global.asax
The Error events have two methods to handle the
exception:
Question - Define Custom Error Pages.
Answer - There are many errors that can’t be trapped in
the application code like page not found. To intercept this kind of error,
ASP.NET supports Custom Error Pages that can be specified at two places:
-
Specify application-wide error page settings in the customErrors section of the
Web.config file.
-
Specify an error page for a specific Web form in the ErrorPage attribute of the
Web form’s @ Page directive
Question - Why is exception
handling important for an application?
Answer - .Exception handling is used to prevent
application from being stuck due to unusual occurrences. If the exceptions are
handled properly, the application will never get terminated abruptly.
Question - When can you use tracing with exception
handling?
Answer - You can use tracing with exception handling to
log unanticipated exception to the trace log. The log file can be used to
diagnose unanticipated problems and thus can be corrected.
.NET
Code Security Interview questions with answers
What is code security? What are the types? | Define Principal
object. | Define declarative and imperative security. | Define role-based
security. | Explain code access security. | What is Code group? | Define the
use of Caspol.exe.
.NET Debug
& Trace Interview questions with answers
What is break mode? What are the options to step through
code? | Debug Vs Trace. | Define trace class. Define Listeners collection of
Trace and Debug objects. | Define Trace Switches.
|