Alex Rivera | Logout

In .NET, what if something fails in the catch block, will finally always get called?

Asked 2009-02-24T15:03:28.993
16

In a try/catch/finally block like:

try
{

}
catch()
{
   // code fails here
}
finally
{ 

}

So if there is an exception in the catch block, will finally always get called?

What if there is no finally, will the code after the catch block get run?

Edit
Report

1 Answer

0

If an exception occurs in the catch block, all the code in finally would still be executed. If there is an exception handler higher up in the stack (e.g. caller of this function), it will catch this exception. Else result in an unhandled exception and bring your app down.

The code after the point of exception in the catch block will not get called.

answered 2009-02-24T15:07:48.453

Your Answer