Files
mercury/java/runtime/Exception.java
Peter Wang 26498eb230 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.
2009-08-03 05:13:55 +00:00

31 lines
920 B
Java

//
// Copyright (C) 2009 The University of Melbourne.
// This file may only be copied under the terms of the GNU Library General
// Public License - see the file COPYING.LIB in the Mercury distribution.
//
package jmercury.runtime;
public class Exception extends java.lang.Error {
// 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;
}
}
}