Is it possible for one language to know about exceptions that are raised by a different language?

A call to a C function raises an exception, if the function returns BP_ERROR. The global C variable exception stores the type of the exception. The exception can be caught by an ancestor catcher, just like any exceptions that are raised by built-ins. The call java_method throws java_exception(Goal) if the Java method is not defined, or if the Java method throws some exception. The exception java_exception(Goal) can also be caught by an ancestor catcher in Prolog.

The C function initialize_bprolog returns BP_ERROR if the B-Prolog system cannot be initialized, e.g., the environment variable BPDIR is not set. The C functions bp_call_string, bp_call_term, and bp_next_solution return BP_ERROR if any exception is raised by the Prolog program.

In the current version of JIPL, the methods Plc.exec and Plc.call return boolean, and, thus, cannot tell whether or not an exception has occurred in the Prolog execution. Your program must take the responsibility to inform Java about any exceptions that are raised in Prolog. In order to do so, the Prolog program should catch all exceptions, and should set the appropriate member variables of the Java object that started the Prolog program. After Plc.exec or Plc.call returns, the Java program can check the member variables to see whether exceptions have occurred.

Neng-Fa Zhou 2013-01-25