I came around to a piece of code for Base64 encoding. While reading it I stumbled upon something like this:
try {
// GZip -> Base64 -> ByteArray
baos = new java.io.ByteArrayOutputStream();
b64os = new OutputStream( baos, ENCODE | options );
gzos = new java.util.zip.GZIPOutputStream( b64os );
gzos.write( source, off, len );
gzos.close();
} // end try
catch( java.io.IOException e ) {
// Catch it and then throw it immediately so that
// the finally{} block is called for cleanup.
throw e;
} // end catch
finally {
try{ gzos.close(); } catch( Exception e ){}
try{ b64os.close(); } catch( Exception e ){}
try{ baos.close(); } catch( Exception e ){}
} // end finally
As you see the IOException is caught in a catch Block and immediately rethrown and it does not seems to be a mistake, because the comment even describes the action and names the execution of the finally block as the purpose.
But wouldn't the finally block be called anyway?
Sources: