Performing a code scan with Fortify detects the following vulnerability in my code. Which tells me the following:
If the catch blocks are several, it can be uncomfortable and repetitive, but if you "condense" catch blocks by getting a high class Exception level, you can hide exceptions that require a special treatment or that should not be obtained at this point of the Program. Basically, filtering an exception too broad frustrates the purpose of written Java exceptions. Also, it could become especially dangerous if the program grows and starts to launch new types of exceptions.
The code is as follows:
try{ gzos.close(); } catch( Exception e ){}
try{ b64os.close(); } catch( Exception e ){}
try{ baos.close(); } catch( Exception e ){}
The 3 blocks throw the exception of type IOException
. I have two possible solutions which are the following:
//Manera 1
try{ gzos.close(); } catch( IOException e ){}
try{ b64os.close(); } catch( IOException e ){}
try{ baos.close(); } catch( IOException e ){}
//Manera 2
try{ gzos.close();
b64os.close();
baos.close(); } catch( IOException e ){}
Now the question is as follows: How do I handle the exception correctly?