...
If an error occurs in the try block (the // Do operations
section), it will propagate out of doOperation
, and be printed as the "thrown exception". If an error occurs while closing the reader
, that error will propagate out of doOperation
, and be printed as the "thrown exception". But if both errors occur, the try-block error will be the one that propagates out of doOperation
, and be printed as the "thrown exception". The close error gets suppressed, and will be printed as the "supprssed exception". In all cases the reader
is safely closed.
Note that this example is for illustrative purposes only. Compliant code will do proper exception handling, rather than simply printing exceptions to the console. For more information, see ERR00-J. Do not suppress or ignore checked exceptions.
Risk Assessment
Failure to handle an exception in a finally
block can lead to unexpected results.
...