Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exception is caught when Exception is not thrown

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 a MLPMMLExportException.

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);
    }
}
like image 527
DesirePRG Avatar asked Dec 18 '22 22:12

DesirePRG


1 Answers

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!

like image 67
Vihar Avatar answered Dec 25 '22 22:12

Vihar