Tuesday 15 March 2011

Exception Interview Questions

What’s difference between System exceptions and Application exceptions?

a. All exception derives from Exception Base class i.e. System.Exception class. Exceptions can be generated
programmatically or can be generated by system.
Application Exception serves as the base class for all application-specific exception classes. It derives from
Exception but does not provide any extended functionality. You should derive your custom application exceptions
from Application Exception.

b. Application exception are used when we want to define user defined exception. While system exception are all
which are defined by .NET.

Will the finally block get executed if an exception has not occurred?
Yes.

What’s the C# syntax to catch any possible exception?
A catch block that catches the exception of type System.Exception. You can also omit the parameter data type in this case and just write catch {}.

Can multiple catch blocks be executed for a single try statement?

No. Once the proper catch block processed, control is transferred to the finally block .

If we write a goto  or a return statement in try and catch block will the finally block execute ?

The code in the finally always runs even if  there are statements like goto or a return statements.


No comments:

Post a Comment