Wanted: multiple exception-type catch blocks

March 12, 2003 11:29 AM

The following would be incredibly simple to implement in the compiler, would require no VM changes, and would tidy up a lot of source code. How about it, Sun. With a bit of a push, you could get this into 1.5 easily.

(Just a spoonful of syntactic sugar helps the medicine go down...)

try {
   // blah
} catch (RemoteException, NamingException, CreateException
    as Exception e) {
   // blah

Obviously, the ‘target’ exception type would have to be a superclass of all the exception types being caught in that block. Any exception that does not match the types in the list falls through, even if it is still a subclass of the target exception.

The only downside of the way I've written it is that it introduces ‘as’ as a new keyword, which might break some code, but you could always cheat and substitute some kind of punctuation instead.

Previously: HTML peeve: image captions

Next: One last bit of new-apartment bragging...