I'm not an exception hater, but I do dislike the way Java makes you deal with multiple exception types. Take something trivial like reflection:
try {
Field field = someClass.getDeclaredField(someField);
someValue = field.getInt(Barcode.class);
} catch (SecurityException e) {
// do something with the exception
} catch (NoSuchFieldException e) {
// do something else with the exception
}
Now, the truth is that something and something else are almost always the same thing. I'm probably not going to do something different with SecurityException than I will with NoSuchFieldException. I'm going to log/wrap/deal with the exceptions in a generic way. I hate writing duplicate code so much, I'm much more likely to simply write this:
try {
Field field = someClass.getDeclaredField(someField);
someValue = field.getInt(Barcode.class);
} catch (Exception e) {
// do something with the exception
}
However, that is definitely not the same behavior. That code catches all exceptions. In general, I would prefer that unchecked exceptions be passed on unmolested. However, I don't want to have write multiple catch blocks if I don't have to. What I'd really like something like this:
try {
Field field = someClass.getDeclaredField(someField);
someValue = field.getInt(Barcode.class);
} catch (SecurityException, NoSuchFieldException as Exception e) {
// do something else with the exception
}
In my mind, that's the neatest way to uniformly deal with multiple exceptions. If you need to do something different with SecurityException than NoSuchFieldException, you can catch them separately.
The Java compiler wouldn't need to do anything special to support this. As far as I know, two entries in the exception table for a method can point to the same exception handler code. So, it's simply a matter of syntax.