Submitted On 01-MAR-2002
marpe581
Not a very nice solution in my opinion. It still forces the
use of repeated code (the calls to the exception handler).
I like it the ADA way, where you can specify the differrent
exceptions and handle them in a common way.
Submitted On 27-OCT-2006
greggwon
This should be a language feature, it really does help to solve problems with code correctness and code reduction.
Submitted On 01-FEB-2009
With regards to "the common action can easily be encapsulated in a method", this is in general not true if the common action involves assigning to a number of local variables, as has been the case in a number of instances of this I have seen.
Submitted On 08-MAY-2009
Alberto.Nipoti
I think this would be really useful. A typical situation where I wished this feature existed: you have a piece of code that uses reflection *and* performs some other operations.
All reflection-related exceptions (NoSuchMethodException, InvocationTargetException, etc.) usually indicate either a programming error or a severe installation/configuration mistake... you usually want to re-throw them wrapped in some fatal runtime exception. Other exceptions are possible and must be handled in some layer of the application.
If every exception hierarchy was perfectly designed, there would probably be no need for this, but as a designer I know too well that exceptions are perhaps the hardest part of a design...
Submitted On 19-NOV-2009
Sampo
This is not "an exceedingly minor problem", but the single most irritating issue in the entire language! If the code is 2-3 lines of code it's not worth creating a method for it, but this can still create 50 lines of code if there are ten different exceptions to catch. This is especially relevant where there are many different types of failure cases which should be distinguished, in which case an exception hierarchy doesn't help. There are also lots of cases in the JRE itself where a suitable hierarchy does not exist (such as reflection mentioned above)!
Relating to the implementation, within a "catch (AException, BException e)", e should be of the most specific common supertype of AException and BException. However, a "throw e" command should take into account that e can only be of types AException and BException. This would allow writing for example
catch (AException, BException, CException e) {
log("Error: " + e.getMessage());
throw e
}
without losing the exception type information.
PLEASE take this into serious consideration!
Submitted On 19-NOV-2009
Sampo
See also comments on RFE #4909760 for more use cases where this would be necessary.
PLEASE NOTE: JDK6 is formerly known as Project Mustang
|