Exception Handling



1. What are the two diff types of error?  

Run time error and Compile time error


2. What is the base class from which all the exceptions are derived ?  

System.Exception class


3. What are the two main kind of exceptions class?  

System Exception-- Mainly used for inbuilt exceptions like Null Ref Exception,Overflow Exception,Argument ....etc Application Exception-This class is used for user defined exceptions.


4. How to you handle error in C#?  

By using try ,catch and finally blocks. try-contains the code which might throw an exception catch-deals with various error conditions finally-does the cleaning up.



5. Does finally get executed if the code throws an error ?  

Finally is always executed.


6. Is it mandatory for a piece of code to have catch or finally when try block is there ?  

Yes. If a try block is there then either catch or finally has to be there or else a compiler error is generated.


7. Can finally bock have return statement ?  

No,a compile time error is generated. Thats bc finally contains the clean up code.


8. Can there be many catch statements for a single try block ?  

Yes.But the rule is most specific exceptions should be caught first.


9. What is checked and unchecked operator.  

checked--checks for the error and throws an exception. unchecked--does not check for the error .truncates the data and prints it..used mainly while casting.


10. Does foll code work ?  

try {} catch(Exception e) {} catch(Exception e) {} No,two catch block cannot have same exception classes.


11. Whats the diff bt throw and throw e ?  

throw-- throws the exception. throw is internally compiled to rethrow throw e--throws the exception and resets the stack trace to current catch location. internally compiled to throw which taken an exception parameter as input.


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

The codes in then finally always run even if there are statements like goto or a return statement.


13. Can two catch blocks be executed?  

No, once the proper catch section is executed the control goes finally to block. So there will not be any scenarios in which multiple catch blocks will be executed.


14. what is the difference between System exceptions and Application exceptions?  

All exception derives from Exception Base class. Exceptions can be generated programmatically or can be generated by system. Application Exception serves as the base class for all applicationspecific exception classes. It derives from Exception but does not provide any extended functionality. You should derive your custom application exceptions from Application Exception. Application exception is used when we want to define user-defined exception, while system exception is all that is defined by .NET.


15. Can multiple catch blocks be executed?  

No, Multiple catch blocks can’t be executed. Once the proper catch code executed, the control is transferred to the finally block and then the code that follows the finally block gets executed.


16. List down the commonly used types of exceptions in .Net?  

ArgumentException, ArgumentNullException , ArgumentOutOfRangeException, ArithmeticException, DivideByZeroException ,OverflowException , IndexOutOfRangeException ,InvalidCastException ,InvalidOperationException , IOEndOfStreamException , NullReferenceException , OutOfMemoryException , StackOverflowException etc.


17. What are Custom Exceptions?  

Sometimes there are some errors that need to be handeled as per user requirements. Custom exceptions are used for them and are used defined exceptions.


18. Does C# have a throws clause?  

No, unlike Java, C# does not require the developer to specify the exceptions that a method can throw.


19. Is using of exceptions in C# recommended?  

Yes, exceptions are the recommended error handling mechanism in .NET Framework.


.Net Interview Question

PHP Interview Question

Java Interview Question

AngularJS Interview Questions