PageRenderTime 48ms CodeModel.GetById 25ms app.highlight 16ms RepoModel.GetById 2ms app.codeStats 0ms

/interpreter/tags/at2-build060407/src/edu/vub/at/exceptions/InterpreterException.java

http://ambienttalk.googlecode.com/
Java | 134 lines | 73 code | 20 blank | 41 comment | 12 complexity | 3bb9fc787f5dd4200df1e3fa7abb6dc2 MD5 | raw file
  1/**
  2 * AmbientTalk/2 Project
  3 * ATException.java created on Jul 13, 2006 at 8:24:20 PM
  4 * (c) Programming Technology Lab, 2006 - 2007
  5 * Authors: Tom Van Cutsem & Stijn Mostinckx
  6 * 
  7 * Permission is hereby granted, free of charge, to any person
  8 * obtaining a copy of this software and associated documentation
  9 * files (the "Software"), to deal in the Software without
 10 * restriction, including without limitation the rights to use,
 11 * copy, modify, merge, publish, distribute, sublicense, and/or
 12 * sell copies of the Software, and to permit persons to whom the
 13 * Software is furnished to do so, subject to the following
 14 * conditions:
 15 *
 16 * The above copyright notice and this permission notice shall be
 17 * included in all copies or substantial portions of the Software.
 18 *
 19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 20 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
 21 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 22 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 23 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
 24 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 25 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 26 * OTHER DEALINGS IN THE SOFTWARE.
 27 */
 28package edu.vub.at.exceptions;
 29
 30import edu.vub.at.eval.InvocationStack;
 31import edu.vub.at.objects.ATObject;
 32import edu.vub.at.objects.ATStripe;
 33import edu.vub.at.objects.natives.NATException;
 34
 35import java.io.PrintStream;
 36import java.io.PrintWriter;
 37
 38/**
 39 * TODO tvcutsem Shouldn't we parameterize NATExceptions with an ATContext and possibly
 40 * also an ATAbstractGrammar for evaluation errors. This allows the user to inspect
 41 * both which expression was evaluated at exception-raising-time and allows him to inspect
 42 * the context at exception-raising-time.
 43 * 
 44 * @author smostinc
 45 */
 46public abstract class InterpreterException extends Exception {
 47
 48	private static final long serialVersionUID = 511962997881825680L;
 49
 50	// The ambienttalk stack trace of the exception
 51	protected final InvocationStack runtimeStack_;
 52
 53	private final Throwable cause_;
 54
 55	public InterpreterException() {
 56		super();
 57		runtimeStack_ = InvocationStack.captureInvocationStack();
 58		cause_ = null;
 59	}
 60
 61	public InterpreterException(String message, Throwable cause) {
 62		super(message);
 63		// Backport from JDK 1.4 to 1.3
 64		// super(message, cause);
 65		cause_ = cause;
 66		runtimeStack_ = InvocationStack.captureInvocationStack();
 67	}
 68
 69	public InterpreterException(String message) {
 70		super(message);
 71		runtimeStack_ = InvocationStack.captureInvocationStack();
 72		cause_ = null;
 73	}
 74
 75	public InterpreterException(Throwable cause) {
 76		// Backport from JDK 1.4 to 1.3
 77		// super(cause);
 78		cause_ = cause;
 79		runtimeStack_ = InvocationStack.captureInvocationStack();
 80	}
 81
 82	public void printAmbientTalkStackTrace(PrintStream out) {
 83		runtimeStack_.printStackTrace(out);
 84	}
 85
 86	public ATObject getAmbientTalkRepresentation() {
 87		return new NATException(this);
 88	}
 89
 90	public abstract ATStripe getStripeType();
 91
 92	public String getMessage() {
 93		if (cause_ == null) {
 94			return super.getMessage();
 95		} else {
 96			return super.getMessage() + " caused by " + cause_.getMessage();
 97		}
 98	}
 99
100	/* backport from 1.4 interface to 1.3 */
101
102	public Throwable getCause() {
103		return cause_;
104	}
105
106	public void printStackTrace(PrintStream out) {
107		if (cause_ == null) {
108			super.printStackTrace(out);
109		} else {
110			super.printStackTrace(out);
111			out.print(" caused by:");
112			cause_.printStackTrace(out);
113		}
114	}
115
116	public void printStackTrace(PrintWriter out) {
117		if (cause_ == null) {
118			super.printStackTrace(out);
119		} else {
120			super.printStackTrace(out);
121			out.print(" caused by:");
122			cause_.printStackTrace(out);
123		}
124	}
125
126	public String toString() {
127		if (cause_ == null) {
128			return super.toString();
129		} else {
130			return super.toString() + " caused by " + cause_.toString();
131		}
132	}
133
134}