001: package sisc.interpreter;
002:
003: import java.io.PrintStream;
004: import java.io.PrintWriter;
005: import sisc.util.Util;
006: import sisc.data.Value;
007: import sisc.data.Symbol;
008: import sisc.data.Pair;
009: import sisc.data.Procedure;
010: import sisc.data.SchemeString;
011: import sisc.interpreter.Context;
012: import sisc.interpreter.SchemeCaller;
013: import sisc.interpreter.Interpreter;
014:
015: public class SchemeException extends Exception {
016: public Pair m;
017: public Procedure e, f;
018:
019: public SchemeException(Pair message, Procedure exception_k,
020: Procedure parent_fk) {
021: m = message;
022: e = exception_k;
023: f = parent_fk;
024: }
025:
026: /**
027: * @return the Scheme message Pair as String
028: */
029: public String getMessage() {
030: return m.toString();
031: }
032:
033: /**
034: * @return the bare Scheme message text
035: */
036: public String getMessageText() {
037: return ((Pair) m.car()).cdr().toString();
038: }
039:
040: private String schemeStackTrace() {
041: try {
042: SchemeString res = (SchemeString) Context
043: .execute(new SchemeCaller() {
044: public Object execute(Interpreter r)
045: throws SchemeException {
046: Procedure converter = (Procedure) r.lookup(
047: Symbol.get("error->string"),
048: Util.TOPLEVEL);
049: return r.eval(converter,
050: new Value[] { m, e });
051: }
052: });
053: return "Scheme exception:\n" + res.asString();
054: } catch (Exception e) {
055: return "";
056: }
057: }
058:
059: public void printStackTrace(PrintStream s) {
060: super .printStackTrace(s);
061: s.print(schemeStackTrace());
062: }
063:
064: public void printStackTrace(PrintWriter s) {
065: super .printStackTrace(s);
066: s.print(schemeStackTrace());
067: }
068:
069: }
070:
071: /*
072: * The contents of this file are subject to the Mozilla Public
073: * License Version 1.1 (the "License"); you may not use this file
074: * except in compliance with the License. You may obtain a copy of
075: * the License at http://www.mozilla.org/MPL/
076: *
077: * Software distributed under the License is distributed on an "AS
078: * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
079: * implied. See the License for the specific language governing
080: * rights and limitations under the License.
081: *
082: * The Original Code is the Second Interpreter of Scheme Code (SISC).
083: *
084: * The Initial Developer of the Original Code is Scott G. Miller.
085: * Portions created by Scott G. Miller are Copyright (C) 2000-2007
086: * Scott G. Miller. All Rights Reserved.
087: *
088: * Contributor(s):
089: * Matthias Radestock
090: *
091: * Alternatively, the contents of this file may be used under the
092: * terms of the GNU General Public License Version 2 or later (the
093: * "GPL"), in which case the provisions of the GPL are applicable
094: * instead of those above. If you wish to allow use of your
095: * version of this file only under the terms of the GPL and not to
096: * allow others to use your version of this file under the MPL,
097: * indicate your decision by deleting the provisions above and
098: * replace them with the notice and other provisions required by
099: * the GPL. If you do not delete the provisions above, a recipient
100: * may use your version of this file under either the MPL or the
101: * GPL.
102: */
|