Fwd: JShell /exit with a non-zero error code

Christian Stein sormuras at gmail.com
Sun Jun 25 14:27:34 UTC 2017


Hi!

Copied from: https://stackoverflow.com/questions/44620232/exit-
jshell-with-error-code

How do I /exit a jshell session with a non-zero error code?

*/exit* yields: Process finished with exit code 0
*/exit 1* yields: Process finished with exit code 0
*throw new Error("1")* yields: java.lang.Error thrown: 1 at (#24:1)` and
Process finished with exit code 0
*System.exit(1)* yields: State engine terminated. Restore definitions with:
/reload -restore ... and the jshell session is not terminated.


A bash command like set -e is not available.



It feels like it is intentionally not supported, am I right?


My current work-around is to communicate via file system.
I create an "error token" file in "build.jsh" and check its presence
afterwards:


/open src/main/java/Bach.java
/open src/main/java/Build.java
Path failed = Paths.get("build.jsh.failed");
Files.deleteIfExists(failed)
try {
  Build.main();
} catch (Throwable t) {
  Files.createFile(failed);
}
/exit



Check in calling (.travis.yml) script:


./build.jsh && test ! -f build.jsh.failed



Cheers,
Christian


More information about the kulla-dev mailing list