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
Asked
Active
Viewed 147 times
-2
-
How many different exception types are you expecting?! – Louis Wasserman Oct 27 '16 at 21:21
1 Answers
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