United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
JDK-4554473 : add constructor accepting a Throwable to IllegalArgumentException

Details
Type:
Enhancement
Submit Date:
2001-12-06
Status:
Closed
Updated Date:
2003-06-19
Project Name:
JDK
Resolved Date:
2003-06-19
Component:
core-libs
OS:
generic
Sub-Component:
java.lang
CPU:
generic
Priority:
P4
Resolution:
Duplicate
Affected Versions:
1.4.0
Fixed Versions:

Related Reports
Duplicate:

Sub Tasks

Description

Name: nt126004			Date: 12/06/2001


java version "1.4.0-beta3"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-beta3-b84)
Java HotSpot(TM) Client VM (build 1.4.0-beta3-b84, mixed mode)

	public  void someMethod sampleMethod() {
		try {
			someOtherMethod();
		} catch (Throwable ex) {
			throw new IllegalArgumentException(ex);
		}
		
	}
This does not compile because IllegalArgumentException class does not have
constructor
IllegalArgumentException(Throwable t) even thought it extends from
RuntimeException which does
(Review ID: 136600) 
======================================================================

                                    

Comments
WORK AROUND



Name: nt126004			Date: 12/06/2001


Customer Workaround :
use
 throw (IllegalArgumentException)(new IllegalArgumentException().initCause(ex));
Note the cast is needed or javac complains about not declareing the Throwable
exception in the method header
======================================================================
                                     
2004-06-11
EVALUATION

Believe it or not, this was not an oversight.  When I designed the nested exception facility I thought carefully about which excpeptions should be given a (Throwable) constructor, and came to the conclusion that IllegalArgumentException did not need one, even though it is designed to be extended.  The rationale is that this constructor is designed specifically for use when an input parameter is invalid, not when some lower-level action fails (throwing an exception that demands nesting).  I understand that it's theoretically possible that such an exception is the direct result on an invalid parameter, but it appears impractical for a program to make that determination. 

When the chained excption facility was designed, I was unable to come up with a situation wherein a program would actually want to throw an IllegalArgumentException with a nested Exception.  I am marking this exception incomplete to give the reporter an opportunity to describe such an scenario.  Barring such a scenario, I believe this bug should be closed.

###@###.### 2001-12-06
                                     
2001-12-06



Hardware and Software, Engineered to Work Together