Is there any performance benefit (particularly in C++ or Java) in keeping the size of try block small [aside from it being more informative to the reader as to which statement can throw].
Given the following method where i do not want to throw out of the method.
void function() throws Exception
{
statement1
statement2
statement3 // can throw
statement4
statement5
}
Is it better to do this:
Option 1
void function()
{
try {
statement1
statement2
statement3 // can throw
statement4
statement5
}
catch (...) {
}
}
or
Option 2
void function()
{
statement1
statement2
boolean success = false;
try {
statement3 // can throw
success = true;
}
catch (...) {
}
if (success)
{
statement4
statement5
}
}