United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
JDK-4432337 : Catching multiple exceptions simultaneously

Details
Type:
Enhancement
Submit Date:
2001-03-30
Status:
Closed
Updated Date:
2014-02-26
Project Name:
JDK
Resolved Date:
2011-08-06
Component:
specification
OS:
generic,windows_xp
Sub-Component:
language
CPU:
generic,x86
Priority:
P4
Resolution:
Fixed
Affected Versions:
1.2.2,1.4.2,6,7
Fixed Versions:
7 (rc)

Related Reports
Duplicate:
Duplicate:
Relates:

Sub Tasks

Description

Name: ssT124754			Date: 03/30/2001


java version "1.2.2"
Classic VM (build JDK-1.2.2-001, native threads, symcjit)

If I need to catch three exceptions, say, NamingException, CreateException and
RemoteException (all of which are descendants of java.lang.Exception) and if I
need to take the same action for them I should not be required to catch them
one after the other. Your compiler should allow me to do something like the
following:

Exception exc;
try
{
   //bunch of stuff
}
catch (NamingException, RemoteException, CreateException exc)
{
    exc.getMessage ();
}
(Review ID: 119838) 
======================================================================

                                    

Comments
EVALUATION

Maybe.
                                     
2007-01-19
EVALUATION

I can see why someone would wish for this. However, this just a bit of fancy sugar, and not a very frequent problem. Nor is the burden on the programmer
very great: the common action can easily be encapsulated in a method. In most
cases, the multiple exceptions might well be organized in hierarchy with a
common superclass to avoid this problem. Of course, this might not always
be  possible. 

Altogether, an exceedingly minor problem. We'll take it under consideration.

gilad.bracha@eng 2001-03-30
                                     
2001-03-30



Hardware and Software, Engineered to Work Together