Print suppressed exceptions in JShell

Pavel Rappo pavel.rappo at gmail.com
Mon Nov 3 17:41:11 UTC 2025


>From the user’s perspective, it would be helpful to see suppressed
exceptions. Even though it’s unusual to use try-with-resources (TWR)
in hand-written JShell snippets, some methods _programmatically_ add
suppressed exceptions to the exception they throw, so TWR isn’t
required to see them.


On Thu, Oct 30, 2025 at 11:41 PM Chen Liang <chen.l.liang at oracle.com> wrote:
>
> On a second look, this is a bit more complex - the exception has to be transported. So UserException does not handle suppressed exceptions at all; ExecutionControlForwarder, LocalExecutionControl, StreamingExecutionControl all need to update for suppressed exception handling. In particular, changing the forwarder's protocol might be a bit risky; I wonder if we want to dig into this.
> ________________________________
> From: compiler-dev <compiler-dev-retn at openjdk.org> on behalf of Chen Liang <chen.l.liang at oracle.com>
> Sent: Thursday, October 30, 2025 6:35 PM
> To: Pavel Rappo <pavel.rappo at gmail.com>; compiler-dev at openjdk.org <compiler-dev at openjdk.org>
> Subject: Re: Print suppressed exceptions in JShell
>
> I think it is probably just an oversight. This seems to be printed by JShellTool::displayEvalException, which shouldn't be too hard to add printing for suppressed exceptions.
>
> -Chen
>
>
> Confidential – Oracle Internal
> ________________________________
> From: compiler-dev <compiler-dev-retn at openjdk.org> on behalf of Pavel Rappo <pavel.rappo at gmail.com>
> Sent: Thursday, October 30, 2025 5:06 PM
> To: compiler-dev at openjdk.org <compiler-dev at openjdk.org>
> Subject: Print suppressed exceptions in JShell
>
> Is there any reason why JShell does not print out suppressed
> exceptions? I think it would be good to print them.
>
>     jshell> new Throwable()
>     $1 ==> java.lang.Throwable
>
>     jshell> new Error()
>     $2 ==> java.lang.Error
>
>     jshell> $1.addSuppressed($2)
>
>     jshell> throw $1
>     |  Exception java.lang.Throwable
>     |        at (#1:1)
>
> -Pavel


More information about the compiler-dev mailing list