JDK-4554473 : add constructor accepting a Throwable to IllegalArgumentException
  • Type: Enhancement
  • Component: core-libs
  • Sub-Component: java.lang
  • Affected Version: 1.4.0
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: generic
  • CPU: generic
  • Submitted: 2001-12-06
  • Updated: 2003-06-19
  • Resolved: 2003-06-19
Related Reports
Duplicate :  
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 ======================================================================
11-06-2004

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
06-12-2001