Name: gm110360 Date: 03/24/2003
A DESCRIPTION OF THE REQUEST :
More Throwables should support nested Throwables. The root Throwable class has some very nice API for this support, but subclasses rarely take advantage of it. Constructors that tack the cause in the argument encourage developers to use it, and write better code.
I am currently catching a declared Exception from a library. This libary exception indicates an illegal state. I'd like to throw an IllegalStateException, but have to jump through some hoops because IllegalStateException's constructor does not take a nested Throwable.
EXPECTED VERSUS ACTUAL BEHAVIOR :
I'd like to use the code
throw new IllegalStateException("bad state details",myException);
If I use that code, it won't compile.
---------- BEGIN SOURCE ----------
A test case containing
throw new IllegalStateException("bad state details",new Exception("test"));
should reproduce the problem nicely.
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
I can use
Throwable thrown = new IllegalStateException("message");
but the shorter API will encourage others to nest exceptions much better.
(Review ID: 182957)
Name: nt126004 Date: 05/15/2003
FULL PRODUCT VERSION :
java version "1.4.1_02"
A DESCRIPTION OF THE PROBLEM :
To my surprise in JDK 1.4.1_02 some exceptions like
do not support constructors for exception chaining,
e.g. IllegalStateException(Throwable cause)
The method Throwable.initCause(Throwable)
however allows the setting of the cause.
The result is ugly code if I want to set the cause:
throw new new IllegalStateException(theCause);
I must write:
IllegalStateException ex = new IllegalStateException();
Or is this omission of constructors on purpose for some reason?
(Review ID: 185824)