Class InterpreterException

This class defines an interpreter exception which consists of a message, eventually a text location and a back trace. This is typically thrown by the interpreter which has access to the text location and the back trace. The interpreter exception class cannot be sub-classed by the application programmer. But the application programmer can create and also throw interpreter exceptions.

The application programmer can provide an arbitrary exception term to the basic constructor. A copy of the given term will be created and stored in the exception. The copied exception term can be retrieved via the method getValue().The location of the message term depends on the form of the exception term. The following exception terms are recognized:

error(Message, Context)
warning(Message, Context)
cause(Exception, Exception)

Alternatively the application programmer can provide a message and a context. This time error(Message, Context) will be created. Or the application programmer can provide a message, a context and a type. This will create <fun>(Message, Context). Further the constructor that takes two interpreter exceptions will create a cause/1 exception term.

There are a couple of convenience methods to create the context. The method fetchStack() retrieves the back trace from the current call chain. The method fetchPos() adds the text position to a back trace. The method fetchLoc() adds the text location to a back trace.

The detailed message methods getMessage() will give the message term without the context. The variant without an interpreter argument can only display skeletons. The variant with an interpreter argument will attempt a user-friendly display. The printStackTrace() methods will attempt to produce a user-friendly display of the message together with the context. The variant without a writer argument will display to the error stream. The variant with a writer argument will produce the stack trace to this writer.

There are a couple of convenience methods to analyse the exception term. The method exceptionType() will return the Message when the original exception term does have the form <fun>(Message,_) or cause(<fun>(Message,_),_). Otherwise the method will return null. The method causeChainRest() will return the Rest when the original exception term does have the form cause(_,Rest). Otherwise the method will return null.



public class InterpreterException extends Exception {
public InterpreterException(Object t);
public InterpreterException(InterpreterMessage msg, Object ctxt);
public InterpreterException(InterpreterMessage msg, Object ctxt,
String type);
public InterpreterException(InterpreterException e1,
InterpreterException e2);

public Object getValue();
public static Object fetchStack(Interpreter inter);
public static Object fetchLoc(Object t, PositionKey pos,
Interpreter inter);
public static Object fetchPos(Object t, String line,
Interpreter inter);
public String getMessage();
public String getMessage(Interpreter inter);
public void printStackTrace(Interpreter inter)
throws InterpreterMessage;
public void printStackTrace(Writer pw, Interpreter inter)
throws InterpreterMessage;
public InterpreterMessage exceptionType(String fun);
public InterpreterException causeChainRest();