001: /* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
002: *
003: * ***** BEGIN LICENSE BLOCK *****
004: * Version: MPL 1.1/GPL 2.0
005: *
006: * The contents of this file are subject to the Mozilla Public License Version
007: * 1.1 (the "License"); you may not use this file except in compliance with
008: * the License. You may obtain a copy of the License at
009: * http://www.mozilla.org/MPL/
010: *
011: * Software distributed under the License is distributed on an "AS IS" basis,
012: * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
013: * for the specific language governing rights and limitations under the
014: * License.
015: *
016: * The Original Code is Rhino code, released
017: * May 6, 1999.
018: *
019: * The Initial Developer of the Original Code is
020: * Netscape Communications Corporation.
021: * Portions created by the Initial Developer are Copyright (C) 1997-1999
022: * the Initial Developer. All Rights Reserved.
023: *
024: * Contributor(s):
025: * Norris Boyd
026: * Bojan Cekrlic
027: * Hannes Wallnoefer
028: *
029: * Alternatively, the contents of this file may be used under the terms of
030: * the GNU General Public License Version 2 or later (the "GPL"), in which
031: * case the provisions of the GPL are applicable instead of those above. If
032: * you wish to allow use of your version of this file only under the terms of
033: * the GPL and not to allow others to use your version of this file under the
034: * MPL, indicate your decision by deleting the provisions above and replacing
035: * them with the notice and other provisions required by the GPL. If you do
036: * not delete the provisions above, a recipient may use your version of this
037: * file under either the MPL or the GPL.
038: *
039: * ***** END LICENSE BLOCK ***** */
040:
041: // API class
042: package org.mozilla.javascript;
043:
044: /**
045: * Java reflection of JavaScript exceptions.
046: * Instances of this class are thrown by the JavaScript 'throw' keyword.
047: *
048: * @author Mike McCabe
049: */
050: public class JavaScriptException extends RhinoException {
051: static final long serialVersionUID = -7666130513694669293L;
052:
053: /**
054: * @deprecated
055: * Use {@link WrappedException#WrappedException(Throwable)} to report
056: * exceptions in Java code.
057: */
058: public JavaScriptException(Object value) {
059: this (value, "", 0);
060: }
061:
062: /**
063: * Create a JavaScript exception wrapping the given JavaScript value
064: *
065: * @param value the JavaScript value thrown.
066: */
067: public JavaScriptException(Object value, String sourceName,
068: int lineNumber) {
069: recordErrorOrigin(sourceName, lineNumber, null, 0);
070: this .value = value;
071: }
072:
073: public String details() {
074: try {
075: return ScriptRuntime.toString(value);
076: } catch (RuntimeException rte) {
077: // ScriptRuntime.toString may throw a RuntimeException
078: if (value == null) {
079: return "null";
080: } else if (value instanceof Scriptable) {
081: return ScriptRuntime
082: .defaultObjectToString((Scriptable) value);
083: } else {
084: return value.toString();
085: }
086: }
087: }
088:
089: /**
090: * @return the value wrapped by this exception
091: */
092: public Object getValue() {
093: return value;
094: }
095:
096: /**
097: * @deprecated Use {@link RhinoException#sourceName()} from the super class.
098: */
099: public String getSourceName() {
100: return sourceName();
101: }
102:
103: /**
104: * @deprecated Use {@link RhinoException#lineNumber()} from the super class.
105: */
106: public int getLineNumber() {
107: return lineNumber();
108: }
109:
110: private Object value;
111: }
|