Is it possible for one language to know about exceptions 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 tells the type of the exception. The exception can be caught by an ancestor catcher just like any exceptions raised by built-ins. The call java_method throws java_exception(Goal) if the Java method is not defined or 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 returns 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 of any exceptions raised in Prolog. To do so, the Prolog program should catch all exceptions and set 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 2011-05-12