~ubuntu-branches/ubuntu/karmic/rhino/karmic

« back to all changes in this revision

Viewing changes to src/org/mozilla/javascript/EcmaError.java

  • Committer: Bazaar Package Importer
  • Author(s): Jerry Haltom
  • Date: 2005-03-19 16:56:07 UTC
  • mto: (11.1.1 squeeze)
  • mto: This revision was merged to the branch mainline in revision 3.
  • Revision ID: james.westby@ubuntu.com-20050319165607-geu3j3fnqlkpqkh1
Tags: upstream-1.6.R1
ImportĀ upstreamĀ versionĀ 1.6.R1

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2
 
 *
3
 
 * The contents of this file are subject to the Netscape Public
4
 
 * License Version 1.1 (the "License"); you may not use this file
5
 
 * except in compliance with the License. You may obtain a copy of
6
 
 * the License at http://www.mozilla.org/NPL/
7
 
 *
8
 
 * Software distributed under the License is distributed on an "AS
9
 
 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express oqr
10
 
 * implied. See the License for the specific language governing
11
 
 * rights and limitations under the License.
12
 
 *
13
 
 * The Original Code is Rhino code, released
14
 
 * May 6, 1999.
15
 
 *
16
 
 * The Initial Developer of the Original Code is Netscape
17
 
 * Communications Corporation.  Portions created by Netscape are
18
 
 * Copyright (C) 1997-1999 Netscape Communications Corporation. All
19
 
 * Rights Reserved.
20
 
 *
21
 
 * Contributor(s): 
22
 
 * Roger Lawrence
23
 
 * 
24
 
 * Alternatively, the contents of this file may be used under the
25
 
 * terms of the GNU Public License (the "GPL"), in which case the
26
 
 * provisions of the GPL are applicable instead of those above.
27
 
 * If you wish to allow use of your version of this file only
28
 
 * under the terms of the GPL and not to allow others to use your
29
 
 * version of this file under the NPL, indicate your decision by
30
 
 * deleting the provisions above and replace them with the notice
31
 
 * and other provisions required by the GPL.  If you do not delete
32
 
 * the provisions above, a recipient may use your version of this
33
 
 * file under either the NPL or the GPL.
34
 
 */
35
 
 
36
 
// API class
37
 
 
38
 
package org.mozilla.javascript;
39
 
 
40
 
/**
41
 
 * The class of exceptions raised by the engine as described in 
42
 
 * ECMA edition 3. See section 15.11.6 in particular.
43
 
 */
44
 
public class EcmaError extends RuntimeException {
45
 
 
46
 
    /**
47
 
     * Create an exception with the specified detail message.
48
 
     *
49
 
     * Errors internal to the JavaScript engine will simply throw a
50
 
     * RuntimeException.
51
 
     *
52
 
     * @param nativeError the NativeError object constructed for this error
53
 
     * @param sourceName the name of the source reponsible for the error
54
 
     * @param lineNumber the line number of the source
55
 
     * @param columnNumber the columnNumber of the source (may be zero if
56
 
     *                     unknown)
57
 
     * @param lineSource the source of the line containing the error (may be 
58
 
     *                   null if unknown)
59
 
     */
60
 
    public EcmaError(NativeError nativeError, String sourceName, 
61
 
                     int lineNumber, int columnNumber, String lineSource) 
62
 
    {
63
 
        super("EcmaError");
64
 
        errorObject = nativeError;
65
 
        this.sourceName = sourceName;
66
 
        this.lineNumber = lineNumber;
67
 
        this.columnNumber = columnNumber;
68
 
        this.lineSource = lineSource;
69
 
    }
70
 
    
71
 
    /**
72
 
     * Return a string representation of the error, which currently consists 
73
 
     * of the name of the error together with the message.
74
 
     */
75
 
    public String toString() {
76
 
        if (sourceName != null && lineNumber > 0)
77
 
            return errorObject.toString() + " (" + sourceName + 
78
 
               "; line " + lineNumber + ")";
79
 
        else
80
 
            return errorObject.toString();
81
 
    }
82
 
    
83
 
    /**
84
 
     * Gets the name of the error.
85
 
     * 
86
 
     * ECMA edition 3 defines the following
87
 
     * errors: EvalError, RangeError, ReferenceError, 
88
 
     * SyntaxError, TypeError, and URIError. Additional error names
89
 
     * may be added in the future.
90
 
     * 
91
 
     * See ECMA edition 3, 15.11.7.9.
92
 
     * 
93
 
     * @return the name of the error. 
94
 
     */
95
 
    public String getName() {
96
 
        return errorObject.getName();
97
 
    }
98
 
    
99
 
    /**
100
 
     * Gets the message corresponding to the error.
101
 
     * 
102
 
     * See ECMA edition 3, 15.11.7.10.
103
 
     * 
104
 
     * @return an implemenation-defined string describing the error.
105
 
     */
106
 
    public String getMessage() {
107
 
        return errorObject.getMessage();
108
 
    }
109
 
    
110
 
    /**
111
 
     * Get the name of the source containing the error, or null
112
 
     * if that information is not available.
113
 
     */
114
 
    public String getSourceName() {
115
 
        return sourceName;
116
 
    }
117
 
    
118
 
    /**
119
 
     * Returns the line number of the statement causing the error,
120
 
     * or zero if not available.
121
 
     */
122
 
    public int getLineNumber() {
123
 
        return lineNumber;
124
 
    }
125
 
    
126
 
    /**
127
 
     * Get the error object corresponding to this exception.
128
 
     */
129
 
    public Scriptable getErrorObject() {
130
 
        return errorObject;
131
 
    }
132
 
    
133
 
    /**
134
 
     * The column number of the location of the error, or zero if unknown.
135
 
     */
136
 
    public int getColumnNumber() {
137
 
        return columnNumber;
138
 
    }
139
 
    
140
 
    /**
141
 
     * The source of the line causing the error, or zero if unknown.
142
 
     */
143
 
    public String getLineSource() {
144
 
        return lineSource;
145
 
    }
146
 
    
147
 
    private NativeError errorObject;
148
 
    private String sourceName;
149
 
    private int lineNumber;
150
 
    private int columnNumber;
151
 
    private String lineSource;
152
 
}
 
1
/* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
 
2
 *
 
3
 * The contents of this file are subject to the Netscape Public
 
4
 * License Version 1.1 (the "License"); you may not use this file
 
5
 * except in compliance with the License. You may obtain a copy of
 
6
 * the License at http://www.mozilla.org/NPL/
 
7
 *
 
8
 * Software distributed under the License is distributed on an "AS
 
9
 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
 
10
 * implied. See the License for the specific language governing
 
11
 * rights and limitations under the License.
 
12
 *
 
13
 * The Original Code is Rhino code, released
 
14
 * May 6, 1999.
 
15
 *
 
16
 * The Initial Developer of the Original Code is Netscape
 
17
 * Communications Corporation.  Portions created by Netscape are
 
18
 * Copyright (C) 1997-1999 Netscape Communications Corporation. All
 
19
 * Rights Reserved.
 
20
 *
 
21
 * Contributor(s):
 
22
 * Roger Lawrence
 
23
 *
 
24
 * Alternatively, the contents of this file may be used under the
 
25
 * terms of the GNU Public License (the "GPL"), in which case the
 
26
 * provisions of the GPL are applicable instead of those above.
 
27
 * If you wish to allow use of your version of this file only
 
28
 * under the terms of the GPL and not to allow others to use your
 
29
 * version of this file under the NPL, indicate your decision by
 
30
 * deleting the provisions above and replace them with the notice
 
31
 * and other provisions required by the GPL.  If you do not delete
 
32
 * the provisions above, a recipient may use your version of this
 
33
 * file under either the NPL or the GPL.
 
34
 */
 
35
 
 
36
// API class
 
37
 
 
38
package org.mozilla.javascript;
 
39
 
 
40
/**
 
41
 * The class of exceptions raised by the engine as described in
 
42
 * ECMA edition 3. See section 15.11.6 in particular.
 
43
 */
 
44
public class EcmaError extends RhinoException
 
45
{
 
46
    /**
 
47
     * Create an exception with the specified detail message.
 
48
     *
 
49
     * Errors internal to the JavaScript engine will simply throw a
 
50
     * RuntimeException.
 
51
     *
 
52
     * @param sourceName the name of the source reponsible for the error
 
53
     * @param lineNumber the line number of the source
 
54
     * @param columnNumber the columnNumber of the source (may be zero if
 
55
     *                     unknown)
 
56
     * @param lineSource the source of the line containing the error (may be
 
57
     *                   null if unknown)
 
58
     */
 
59
    EcmaError(String errorName, String errorMessage,
 
60
              String sourceName, int lineNumber,
 
61
              String lineSource, int columnNumber)
 
62
    {
 
63
        recordErrorOrigin(sourceName, lineNumber, lineSource, columnNumber);
 
64
        this.errorName = errorName;
 
65
        this.errorMessage = errorMessage;
 
66
    }
 
67
 
 
68
    /**
 
69
     * @deprecated EcmaError error instances should not be constructed
 
70
     *             explicitly since they are generated by the engine.
 
71
     */
 
72
    public EcmaError(Scriptable nativeError, String sourceName,
 
73
                     int lineNumber, int columnNumber, String lineSource)
 
74
    {
 
75
        this("InternalError", ScriptRuntime.toString(nativeError),
 
76
             sourceName, lineNumber, lineSource, columnNumber);
 
77
    }
 
78
 
 
79
    public String details()
 
80
    {
 
81
        return errorName+": "+errorMessage;
 
82
    }
 
83
 
 
84
    /**
 
85
     * Gets the name of the error.
 
86
     *
 
87
     * ECMA edition 3 defines the following
 
88
     * errors: EvalError, RangeError, ReferenceError,
 
89
     * SyntaxError, TypeError, and URIError. Additional error names
 
90
     * may be added in the future.
 
91
     *
 
92
     * See ECMA edition 3, 15.11.7.9.
 
93
     *
 
94
     * @return the name of the error.
 
95
     */
 
96
    public String getName() {
 
97
        return errorName;
 
98
    }
 
99
 
 
100
    /**
 
101
     * Gets the message corresponding to the error.
 
102
     *
 
103
     * See ECMA edition 3, 15.11.7.10.
 
104
     *
 
105
     * @return an implemenation-defined string describing the error.
 
106
     */
 
107
    public String getErrorMessage() {
 
108
        return errorMessage;
 
109
    }
 
110
 
 
111
    /**
 
112
     * @deprecated Use {@link RhinoException#sourceName()} from the super class.
 
113
     */
 
114
    public String getSourceName() {
 
115
        return sourceName();
 
116
    }
 
117
 
 
118
    /**
 
119
     * @deprecated Use {@link RhinoException#lineNumber()} from the super class.
 
120
     */
 
121
    public int getLineNumber() {
 
122
        return lineNumber();
 
123
    }
 
124
 
 
125
    /**
 
126
     * @deprecated Use {@link RhinoException#columnNumber()} from the super class.
 
127
     */
 
128
    public int getColumnNumber() {
 
129
        return columnNumber();
 
130
    }
 
131
 
 
132
    /**
 
133
     * @deprecated Use {@link RhinoException#lineSource()} from the super class.
 
134
     */
 
135
    public String getLineSource() {
 
136
        return lineSource();
 
137
    }
 
138
 
 
139
    /**
 
140
     * @deprecated Always returns result of {@link Context#getUndefinedValue()}.
 
141
     *
 
142
     */
 
143
    public Scriptable getErrorObject()
 
144
    {
 
145
        return Undefined.instance;
 
146
    }
 
147
 
 
148
    private String errorName;
 
149
    private String errorMessage;
 
150
}