jdk/src/share/classes/javax/script/ScriptException.java
author never
Mon, 12 Jul 2010 22:27:18 -0700
changeset 5926 a36f90d986b6
parent 5506 202f599c92aa
child 11276 6a7de6dddc18
permissions -rw-r--r--
6968385: malformed xml in sweeper logging Reviewed-by: kvn
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     2
 * Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package javax.script;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 * The generic <code>Exception</code> class for the Scripting APIs.  Checked
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 * exception types thrown by underlying scripting implementations must be wrapped in instances of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 * <code>ScriptException</code>.  The class has members to store line and column numbers and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * filenames if this information is available.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * @author Mike Grogan
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
public class ScriptException extends Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
    private String fileName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
    private int lineNumber;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
    private int columnNumber;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
     * Creates a <code>ScriptException</code> with a String to be used in its message.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
     * Filename, and line and column numbers are unspecified.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
     * @param s The String to use in the message.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    public ScriptException(String s) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
        super(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
        fileName = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
        lineNumber = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
        columnNumber = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
     * Creates a <code>ScriptException</code> wrapping an <code>Exception</code> thrown by an underlying
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
     * interpreter.  Line and column numbers and filename are unspecified.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
     * @param e The wrapped <code>Exception</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    public ScriptException(Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
        super(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        fileName = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
        lineNumber = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
        columnNumber = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
     * Creates a <code>ScriptException</code> with message, filename and linenumber to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
     * be used in error messages.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     * @param message The string to use in the message
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     * @param fileName The file or resource name describing the location of a script error
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     * causing the <code>ScriptException</code> to be thrown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     * @param lineNumber A line number describing the location of a script error causing
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     * the <code>ScriptException</code> to be thrown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    public ScriptException(String message, String fileName, int lineNumber) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        super(message);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        this.fileName = fileName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        this.lineNumber = lineNumber;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        this.columnNumber = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     * <code>ScriptException</code> constructor specifying message, filename, line number
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     * and column number.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     * @param message The message.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     * @param fileName The filename
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     * @param lineNumber the line number.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     * @param columnNumber the column number.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    public ScriptException(String message,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
            String fileName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
            int lineNumber,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
            int columnNumber) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        super(message);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        this.fileName = fileName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        this.lineNumber = lineNumber;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        this.columnNumber = columnNumber;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     * Returns a message containing the String passed to a constructor as well as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     * line and column numbers and filename if any of these are known.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     * @return The error message.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    public String getMessage() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        String ret = super.getMessage();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        if (fileName != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
            ret += (" in " + fileName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
            if (lineNumber != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
                ret += " at line number " + lineNumber;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
            if (columnNumber != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
                ret += " at column number " + columnNumber;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        return ret;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     * Get the line number on which an error occurred.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     * @return The line number.  Returns -1 if a line number is unavailable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    public int getLineNumber() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        return lineNumber;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     * Get the column number on which an error occurred.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     * @return The column number.  Returns -1 if a column number is unavailable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    public int getColumnNumber() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        return columnNumber;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     * Get the source of the script causing the error.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     * @return The file name of the script or some other string describing the script
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     * source.  May return some implementation-defined string such as <i>&lt;unknown&gt;</i>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     * if a description of the source is unavailable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    public String getFileName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        return fileName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
}