On Thu, 4 Jan 2024 06:56:37 GMT, David Holmes <dhol...@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