-2

I know with Java 7 we can include multiple exceptions in the same catch block and separate them with pipe symbol. My question is for listing them in another file and catching all the exceptions listed in that file

iris-data
  • 11
  • 1
  • 4

1 Answers1

1

You can do something like this:

Set<String> exceptionClasses = ... // load class names from file
try {
    // ...
} catch (Exception e) {
    if (exceptionClasses.contains(e.getClass().getName())) {
        // handle exception
    } else {
        throw e;  // propagate exception
    }
}
shmosel
  • 49,289
  • 6
  • 73
  • 138