RFR: 8322981: Fix 2 locations in JDI that throw IOException without using the "Caused by" exception
Chris Plummer
cjplummer at openjdk.org
Thu Jan 4 17:17:21 UTC 2024
On Thu, 4 Jan 2024 06:56:37 GMT, David Holmes <dholmes at openjdk.org> wrote:
> Setting the cause is good, but do you not also want an informative message?
Not necessary.
public class Test {
public static void main(String[] args) {
try {
try {
throw new Throwable("hello");
} catch (Throwable t) {
throw new Throwable(t);
}
} catch (Throwable t) {
t.printStackTrace(System.out);
}
}
}
produces:
java.lang.Throwable: java.lang.Throwable: hello
at Test.main(Test.java:7)
Caused by: java.lang.Throwable: hello
at Test.main(Test.java:5)
If I change the second throw to:
throw new Throwable(t,"goodbye");
You get:
java.lang.Throwable: goodbye
at Test.main(Test.java:7)
Caused by: java.lang.Throwable: hello
at Test.main(Test.java:5)
So it appears that for the first line of the prinstStackTrace() output, it prints the exception name and then the message if there is one. If there is no message then it instead prints the cause exception name, and its message if it has one.
-------------
PR Comment: https://git.openjdk.org/jdk/pull/17258#issuecomment-1877474604
More information about the serviceability-dev
mailing list