mirror of
https://github.com/Mercury-Language/mercury.git
synced 2026-05-01 17:24:34 +00:00
Make the Java jmercury.runtime.Exception class implement the getMessage()
Branches: main
Make the Java jmercury.runtime.Exception class implement the getMessage()
method for Throwable objects. This is useful when Mercury code is called
from Java code, without the main/2 wrapper.
java/runtime/Exception.java:
Add a method pointer as a class variable.
Implement the getMessage() method by calling the method pointer
if set.
library/exception.m:
On module initialisation set the method pointer in the
jmercury.runtime.Exception class.
Factor out code from report_uncaught_exception_2.
This commit is contained in:
@@ -7,11 +7,24 @@
|
||||
package jmercury.runtime;
|
||||
|
||||
public class Exception extends java.lang.Error {
|
||||
// Should be mercury.univ.Univ_0 but we don't want to depend on the
|
||||
// standard library.
|
||||
// This is to be set when the exception module is initialised, to avoid
|
||||
// having the runtime depend on the standard library.
|
||||
public static MethodPtr getMessageHook = null;
|
||||
|
||||
// Should be univ.Univ_0 but we don't want to depend on the standard
|
||||
// library.
|
||||
public Object exception;
|
||||
|
||||
public Exception(Object exception) {
|
||||
this.exception = exception;
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
if (getMessageHook != null) {
|
||||
Object[] args = new Object[] { exception };
|
||||
return (String) getMessageHook.call___0_0(args);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user