I saw some code like this:
try
{
db.store(mydata);
}
finally
{
db.cleanup();
}
I thought try
is supposed to have a catch
?
Why does this code do it this way?
exceptionjava
I saw some code like this:
try
{
db.store(mydata);
}
finally
{
db.cleanup();
}
I thought try
is supposed to have a catch
?
Why does this code do it this way?
Best Answer
This is useful if you want the currently executing method to still throw the exception while allowing resources to be cleaned up appropriately. Below is a concrete example of handling the exception from a calling method.