-
Enhancement
-
Resolution: Fixed
-
P5
-
7
-
b100
-
x86
-
linux
-
Not verified
A DESCRIPTION OF THE REQUEST :
AssertionError does not have constructors that takes message and a nested throwable. Please add one.
public AssertionError(String message,Throwable cause) { ...}
JUSTIFICATION :
I frequently see code that catches a checked exception that should never be thrown. Sometimes it asserts false, sometimes it throws a RuntimeException, sometimes I'll see an empty catch block, maybe with a comment.
The right thing to do is to throw an AssertionError.
catch(ImpossibleException ie) {
throw new AssertionError("Flow of control should never throw this exception because blah blah blah.",ie);
}
It's a pretty minor request; AssertionError does have an initCause() method that works fine. Developers rarely take that extra simple step to use initCause(). However, they do use the two-argument constructor in many other places. One was surprised not to find it when I pointed out initCause().
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
I'd like to see a new constructor added to AssertionError. Other developers would use that without blinking.
ACTUAL -
The constructor isn't there, so I use initCause. Other developers are astonished when I suggest it.
CUSTOMER SUBMITTED WORKAROUND :
intiCause() works fine for me. Not for others.
AssertionError does not have constructors that takes message and a nested throwable. Please add one.
public AssertionError(String message,Throwable cause) { ...}
JUSTIFICATION :
I frequently see code that catches a checked exception that should never be thrown. Sometimes it asserts false, sometimes it throws a RuntimeException, sometimes I'll see an empty catch block, maybe with a comment.
The right thing to do is to throw an AssertionError.
catch(ImpossibleException ie) {
throw new AssertionError("Flow of control should never throw this exception because blah blah blah.",ie);
}
It's a pretty minor request; AssertionError does have an initCause() method that works fine. Developers rarely take that extra simple step to use initCause(). However, they do use the two-argument constructor in many other places. One was surprised not to find it when I pointed out initCause().
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
I'd like to see a new constructor added to AssertionError. Other developers would use that without blinking.
ACTUAL -
The constructor isn't there, so I use initCause. Other developers are astonished when I suggest it.
CUSTOMER SUBMITTED WORKAROUND :
intiCause() works fine for me. Not for others.
- relates to
-
JDK-8282574 Cleanup unnecessary calls to Throwable.initCause() in jdk.compiler
-
- Resolved
-