01: /* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
02: *
03: * ***** BEGIN LICENSE BLOCK *****
04: * Version: MPL 1.1/GPL 2.0
05: *
06: * The contents of this file are subject to the Mozilla Public License Version
07: * 1.1 (the "License"); you may not use this file except in compliance with
08: * the License. You may obtain a copy of the License at
09: * http://www.mozilla.org/MPL/
10: *
11: * Software distributed under the License is distributed on an "AS IS" basis,
12: * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13: * for the specific language governing rights and limitations under the
14: * License.
15: *
16: * The Original Code is Rhino code, released
17: * May 6, 1999.
18: *
19: * The Initial Developer of the Original Code is
20: * Netscape Communications Corporation.
21: * Portions created by the Initial Developer are Copyright (C) 1997-1999
22: * the Initial Developer. All Rights Reserved.
23: *
24: * Contributor(s):
25: * Norris Boyd
26: *
27: * Alternatively, the contents of this file may be used under the terms of
28: * the GNU General Public License Version 2 or later (the "GPL"), in which
29: * case the provisions of the GPL are applicable instead of those above. If
30: * you wish to allow use of your version of this file only under the terms of
31: * the GPL and not to allow others to use your version of this file under the
32: * MPL, indicate your decision by deleting the provisions above and replacing
33: * them with the notice and other provisions required by the GPL. If you do
34: * not delete the provisions above, a recipient may use your version of this
35: * file under either the MPL or the GPL.
36: *
37: * ***** END LICENSE BLOCK ***** */
38:
39: package org.mozilla.javascript;
40:
41: /**
42: * A wrapper for runtime exceptions.
43: *
44: * Used by the JavaScript runtime to wrap and propagate exceptions that occur
45: * during runtime.
46: *
47: * @author Norris Boyd
48: */
49: public class WrappedException extends EvaluatorException {
50: static final long serialVersionUID = -1551979216966520648L;
51:
52: /**
53: * @see Context#throwAsScriptRuntimeEx(Throwable e)
54: */
55: public WrappedException(Throwable exception) {
56: super ("Wrapped " + exception.toString());
57: this .exception = exception;
58: Kit.initCause(this , exception);
59:
60: int[] linep = { 0 };
61: String sourceName = Context.getSourcePositionFromStack(linep);
62: int lineNumber = linep[0];
63: if (sourceName != null) {
64: initSourceName(sourceName);
65: }
66: if (lineNumber != 0) {
67: initLineNumber(lineNumber);
68: }
69: }
70:
71: /**
72: * Get the wrapped exception.
73: *
74: * @return the exception that was presented as a argument to the
75: * constructor when this object was created
76: */
77: public Throwable getWrappedException() {
78: return exception;
79: }
80:
81: /**
82: * @deprecated Use {@link #getWrappedException()} instead.
83: */
84: public Object unwrap() {
85: return getWrappedException();
86: }
87:
88: private Throwable exception;
89: }
|