Exit jshell with error code

How is /exita jshell session with a non-zero error code?

  • /exit gives: Process terminated with exit code 0
  • /exit 1 gives: Process terminated with exit code 0
  • throw new Error("1") gives: java.lang.Error throw: 1 at (# 24: 1) `and Process terminated with exit code 0
  • System.exit(1)gives: engine condition completed. Restore definitions with: / reload -restore ... and the jshell session does not end.

The bash command is set -enot available.

+6
source share
1 answer

You cannot use /exitjshell with a non-zero error code to exit a regular session. See https://bugs.openjdk.java.net/browse/JDK-8185840 for more details .

jshell (.. vm), System.exit(1) vm .

runnig DOS:

jshell --execution local
|  Welcome to JShell -- Version 9
|  For an introduction type: /help intro

jshell> System.exit(123)

echo Exit Code is %errorlevel%
Exit Code is 123

. http://mail.openjdk.java.net/pipermail/kulla-dev/2017-August/002062.html.

Java 10

Java 10 ​​ /exit, . , . . http://mail.openjdk.java.net/pipermail/kulla-dev/2017-November/002129.html.

/exit jdk-10 + ea-33:

|  Welcome to JShell -- Version 10-ea
|  For an introduction type: /help intro

jshell> /help exit
|
|  /exit
|
|  Leave the jshell tool.  No work is saved.
|  Save any work before using this command
|
|  /exit
|       Leave the jshell tool.  The exit status is zero.
|
|  /exit <integer-expression-snippet>
|       Evaluate the snippet.  If the snippet fails or is not an integer expression,
|       display the error.  Otherwise leave the jshell tool with the
|       value of the expression as the exit status

jshell> /exit 123
|  Goodbye (123)
+4
source

All Articles