Exception is caught when Exception is not thrown
14,464
This is a very famous findbug warning,
according to official documentation this kind of warning is generated when
- method uses a try-catch block that catches Exception objects, but Exception is not thrown within the try block.
- sometimes it also is thrown when we use
catch(Exception e)
to catch all types of exceptions at once, it could mask actual programming problems, so findbugs asks you to catch specific exception, so that run-time exceptions can be thrown which indicate programming problems.
for more understanding(and the solution as well) you can have look at the official documentation.
for your case it seems that statements in try
clause do not throw the exception you are handling in catch
clause
hope this helps!
Good luck!
Related videos on Youtube
Author by
DesirePRG
Updated on July 09, 2022Comments
-
DesirePRG almost 2 years
I have the following code and findbugs complains that "
Exception is caught when Exception is not thrown
" under dodgy code. I do not understand how to solve this.getPMMLExportable
throws aMLPMMLExportException
.public String exportAsPMML(MLModel model) throws MLPmmlExportException { Externalizable extModel = model.getModel(); PMMLExportable pmmlExportableModel = null; try { pmmlExportableModel = ((PMMLModelContainer) extModel).getPMMLExportable(); } catch (MLPmmlExportException e) { throw new MLPmmlExportException(e); } }
-
tkruse over 6 yearsthen you should use "throw e"
-