Consider the below example:
public class Mathematics
{
public int DivisionResult(int x, int y)
{
try
{
return x / y;
}
catch (Exception)
{
return -1;
}
Console.WriteLine(“Will this line be executed or not?”);
}
}
Question: In the above sample the code in Console.WriteLine will be executed or not?
Ans: No it wont since because of the return statement in the try and catch blocks.
If you want to execute some line of code always or at any point of time even if you have return codes. Put your code in finally block. This ensures that your code in finally block is always executed irrespective of written codes.













Nice explanation.
Q:wether any posibility to exicute two or more catch boocks at atime when try block contains two are more errors
Thank you for writing to us.
To my knowledge only one exception will be arised at a given point of time.Though you have many number of chances for getttingexception in your try block.
when ever an exception occured in try it goes to relavent catch block first. from that catch you can either re-throw exception or throw a new exception.If you throw a new exception you have to handle explicitly otherwise CLR handles this by ub-ruptly terminating the program execution.
Note: If you think this is the answer you are looking for then post a comment relavently.
If you require any clarification for the explanation. then write your query along with a sample.
Thank u Sir!
Thnak u sir!
Q:When we use throw in exception handling?
This you can do when ever you want to rethrow any exception. Or you can also create your own exception or custom exception you can throw it in to the system(Project).
well explained