Hi,
What happens when we rethrow an exception in the catch ,who catches that exception.
can anybody give me the example.
thanks,
vinod .
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
VulpesPosted May 27, 2012, 5:58 AM
However, in the following version, there's an outer try/catch statement which can catch the rethrown exception:
vinod kumarPosted May 28, 2012, 2:04 AM
Thanks for the replay.It helped me in understanding exception handling.
Thanks.
vinod kumarPosted May 27, 2012, 12:42 AM
What happens in the code below ,when catch rethrows exception,does it is unhandled.
static void Main()
{
int x, y, z;
try
{
x=1;
y=0;
z=x/y;
}
catch(DivideByZeroException)
{
throw;
}
}
Thanks.
VulpesPosted May 26, 2012, 2:06 PM
1. A catch block in an enclosing try statement in the same method, if there is one, or if there isn't :
2. By a catch block in a try statement in a method earlier in the call stack.
In the case of 2. the call stack is unwound until a method is found which contains a catch block which can handle the exception. If there is no such method, then the exception will cause the application to terminate.
Here's a simple example.
Although a DivideByZero exception occurs in SomeMethod it's rethrown and caught instead in the Main method from which SomeMethod is called: