If you need it to always execute if your try
code succeeds, put it at the end of your try block. It will run as long as the previous code in your try
block runs without an exception.
try
{
// normal code
// code to run if try stuff succeeds
}
catch (...)
{
// handler code
}
finally
{
// finally code
}
If you need alternative exception handling for you "succeded" code, you can always nest your try/catches:
try
{
// normal code
try
{
// code to run if try stuff succeeds
}
catch (...)
{
// catch for the "succeded" code.
}
}
catch (...)
{
// handler code
// exceptions from inner handler don't trigger this
}
finally
{
// finally code
}
If your "succeeded" code has to execute after your finally, use a variable:
bool caught = false;
try
{
// ...
}
catch (...)
{
caught = true;
}
finally
{
// ...
}
if(!caught)
{
// code to run if not caught
}