What happens if both catch and finally blocks throw exception?

Arthur picture Arthur · Sep 27, 2009 · Viewed 12.3k times · Source

What happens if both catch and finally blocks throw exception?

Answer

adrianbanks picture adrianbanks · Sep 27, 2009

When the finally block throws an exception, it will effectively hide the exception thrown from the catch block and will be the one ultimately thrown. It is therefore important to either log exceptions when caught, or make sure that the finally block does not itself throw an exception, otherwise you can get exceptions being thrown that are stifled and never seen.