Add MercuryFatalError exception to the Java runtime.

Add MercuryFatalError, a new Java exception that is intended to be used for a
similar purpose to the C runtime's MR_fatal_error() function.

Throw a MercuryFatalError exception instead of calling System.exit() in a spot.
Calling exit() is fine for executables, but for code that is deployed in an
application server calling exit() may shut down the entire server.

java/runtime/MercuryFatalError.java:
    Add the new exception.

java/runtime/MercuryOptions.java:
    Do not call System.exit() when we encounter an unrecognized
    option in MERCURY_OPTIONS, throw a MercuryFatalError exception
    instead.

    Refactor the process() method in order to avoid indentation.

    Catch NumberFormatExceptions thrown when attempting to convert
    integer option values; rethrow them as MercuryFatalErrors.
    (XXX the C version of the runtime just ignores this error.)

java/runtime/JavaInternal.java:
    Catch and report MercuryFatalErrors in the runMain() method.

java/runtime/MercuryWorkerThread.java:
    Add an XXX about a call to System.exit() here.
This commit is contained in:
Julien Fischer
2024-01-19 21:57:20 +11:00
parent 3d71834bf4
commit 89293d8faa
4 changed files with 58 additions and 22 deletions

View File

@@ -61,7 +61,8 @@ public class MercuryWorkerThread extends MercuryThread
// Make the thread exit after throwing an exception.
break;
} catch (Throwable e) {
// Some other error occured. bail out.
// Some other error occured, bail out.
// XXX We should avoid calling exit() here.
System.err.println("Uncaught exception: " +
e.toString());
System.err.println(e.getMessage());