return executor.internalEvaluate(arguments[0]);
} catch (CALExecutorException.ExternalException.PrimThrowFunctionException primThrowException) {
//the Exception.throw function was called
return arguments[1].apply(new NValObject(primThrowException.getCause()));
} catch (CALExecutorException.ExternalException.ForeignOrPrimitiveFunctionException foreignFunctionException) {
//an exception occurred while calling a foreign function
return arguments[1].apply(new NValObject(foreignFunctionException.getCause()));
} catch (CALExecutorException.ExternalException.PatternMatchFailure patternMatchFailure) {
return arguments[1].apply(new NValObject(patternMatchFailure));
} catch (CALExecutorException.ExternalException.ErrorFunctionException errorException) {
return arguments[1].apply(new NValObject(errorException));
} catch (Throwable throwable) {
if (throwable instanceof CALExecutorException) {
throw (CALExecutorException)throwable;
}
//todoBI check this for the g-machine
//most likely an unchecked foreign function exception. Could also be a programming error in CAL's Java implementation.
//at the moment we have no way to distinguish these 2 cases.
//todoBI
//One solution is to wrap all calls to foreign functions so that a CALExecutor.CALForeignFunctionException is thrown,
//but this is a performance hit.
return arguments[1].apply(new NValObject(throwable));
}
//todoBI handle CALExecutor.CALTerminatedByClientException. We may want to give code a chance to clean up after
//a client has terminated.
}