3 Replies Latest reply on Jul 13, 2017 2:55 PM by Dalibor.Topic-Oracle

    Exit jshell with error code

    Christian Stein

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

      down votefavorite

       

       

      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