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.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend4days leftRegister
VulpesRank #55 · 29.2K reputationPosted May 27, 2012, 1:58 AM EDT
However, in the following version, there's an outer try/catch statement which can catch the rethrown exception:
VulpesRank #55 · 29.2K reputationPosted May 26, 2012, 10:06 AM EDT
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:
vinod kumar31 reputationPosted May 26, 2012, 8:42 PM EDT
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.
vinod kumar31 reputationPosted May 27, 2012, 10:04 PM EDT
Thanks for the replay.It helped me in understanding exception handling.
Thanks.