Exception handling interview questions and answers with C#.Net


 ASP.NET Error Handling

1)What is an Error?


Error is state or condition of being wrong that prohibit program to compile and run correctly as per the expectation.

2)Types of Errors in Programming?

There are three type errors in programming.

Compile Errors
Runtime Errors
Logical Errors

3)What is Compile time Error?


An errors which are arises at compile time is known as compile time errors.

Due to syntactical mistakes which are occured. 

To run your code you need to fix this errors.

4)What is Runtime time Error?


An errors which are arises at runtime or execution of the program is known as runtime time errors.

Due to improper input given by user.
Ex:Dividing a number by zero

Sometimes due to environment also getting this errors
Ex:Lack of free memory space

We can handle this errors using the exception handling.

5)What is Logical Error?


Due to poor coding getting this errors.

These errors not detecting while compile and runtime.

it is programmer responsibility to identify and fix this errors.

 
6)What is Error Handling?


Error handling is nothing but representing the errors and display meaningful error messages. 

7)What is Error logging?

Error logging allows to find and fix the errors.
Proper way of logging the error, save good amount of time for fixing the issue.

8)What is exception?


Runtime error is known as an exception.

(or)

Exception is an object, which is inherit from Sysytem.Exception class.

Exception is thrown from the code block where problem has occured.

using try, catch , finally and throw keywords we are handling exception.

9)What is try, catch and finally in C#.Net exception handling?

Try - Try block represents the block of code that may cause to the exception.We called the block as protected block.
Catch - Catch block is used catch the exception which are generated in try blcok code
Finally - Finally block always executed weather execption reported or not in try block , Catch block executed or not. 

try
{
   //blcok of code 
}
catch (Exception e)
{
    //excption handling mechanism
}
finally
{
    
}

10)In how many ways handling exceptions in C#?

Three ways we are handling the exceptions 

Application Level
Page Level
Code Level

In addition to above IIS custom handlers.

11) Do we catch all the exceptions in C#.Net?


Some uncatchable exceptios exist in C#.Net.

Examples : OutOfMemoryException and StackOverflowException etc..


12)What is the need of handling exceptions at three levels in C#.Net?
(or)
What is the difference between Code Level , Pagelevel or Application Levele Exception handling?


Code Level: Using try , catch and finally blocks handling the exceptions 

try
{
    //block of code
}
catch (Exception e)
{
    
}
finally
{
  
}

Page Level:

Here also we have try , catch and finally blcoks  but these blocks are optional.

We need to add below event in page.

void Application_Error(object sender, EventArgs e)
{
    Exception exc = Server.GetLastError();
    _________________
    _________________
}

If exception not handling at code level , it will come to above page level

Application Level:

Here also we have try , catch and finally blcoks  

This kind of Exceptions will handled in two ways

Uisng WebConfig file.
Using Global.asax file.

Uisng WebConfig file:

<system.web>
    <customErrors mode="On" defaultRedirect="Page URL">
      <error statusCode="500" redirect="Page URL"/>
    </customErrors>
  </system.web>

Using Global.asax file:

Needs to place below handler in Global.asax file

oid Application_Error(object sender, EventArgs e)
{
    Exception exc = Server.GetLastError();
    _________________
    _________________
}

If exception not handling at code level and page level then it will come to application level.

13)What is debugger in .Net?

Debugger is VisualStudion tool provided by Microsoft.


14) What is debuging in C#.Net?

Run your code step by step is called debuging, due to this programmer is able to identify where the issue exactly.

VisualStudio bydefault having the debugger tool.

Debuging mode: 
In debuging mode, debugger activly monitering your program , So that you closely watch your program
if you want you can pause the program do your changes and start it again.
Due to above code optimiztion not in debug mode.

Release Mode:
Code optimization done 
No intermediatory files hasbeen generated (No log info about compilation)
Most of the code rewritten by runtime so that size reduced a lot.
Run code very fastly

Thanks for visiting this blog. How is the content?. Your comment is great gift to my work. Cheers.

1 comment: