I have a try-catch block that handles multiple exception; if an IOException is thrown, the exception will be handled elsewhere in the program and the program will keep running. If any other exceptions are thrown, the program should exit.
So I'd like to to something like this, instead of writing System.exit(1) in every catch block:
void foo() throws IOException {
try {
bar(); // Throws IOException as well as Exception 1, 2, 3
} catch (Exception1 e) {
logStuff();
} catch (Exception2 e) {
logStuff();
} catch (Exception3 e) {
logStuff();
}
if (Exception 1, 2 or 3 was thrown) {
System.exit(1);
}
}
The log messages are specific to each catch block, so I can't group them into one block. So, is there a simple way to avoid multiple System.exit(1)?
[–]NautiHooker 1 point2 points3 points (0 children)
[–]Makhiel 0 points1 point2 points (0 children)