src/java.scripting/share/classes/javax/script/ScriptException.java
author erikj
Tue, 12 Sep 2017 19:03:39 +0200
changeset 47216 71c04702a3d5
parent 25859 jdk/src/java.scripting/share/classes/javax/script/ScriptException.java@3317bb8137f4
permissions -rw-r--r--
8187443: Forest Consolidation: Move files to unified layout Reviewed-by: darcy, ihse
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
14342
8435a30053c1 7197491: update copyright year to match last edit in jdk8 jdk repository
alanb
parents: 11276
diff changeset
     2
 * Copyright (c) 2005, 2011, 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
11276
6a7de6dddc18 7118546: fix warnings in javax.xml.crypto, javax.script
smarks
parents: 5506
diff changeset
    39
    private static final long serialVersionUID = 8265071037049225001L;
6a7de6dddc18 7118546: fix warnings in javax.xml.crypto, javax.script
smarks
parents: 5506
diff changeset
    40
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
    private String fileName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
    private int lineNumber;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
    private int columnNumber;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
     * Creates a <code>ScriptException</code> with a String to be used in its message.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
     * Filename, and line and column numbers are unspecified.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
     * @param s The String to use in the message.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    public ScriptException(String s) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
        super(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
        fileName = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
        lineNumber = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
        columnNumber = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
     * Creates a <code>ScriptException</code> wrapping an <code>Exception</code> thrown by an underlying
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
     * interpreter.  Line and column numbers and filename are unspecified.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
     * @param e The wrapped <code>Exception</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    public ScriptException(Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
        super(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
        fileName = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
        lineNumber = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        columnNumber = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
     * Creates a <code>ScriptException</code> with message, filename and linenumber to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     * be used in error messages.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     * @param message The string to use in the message
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     * @param fileName The file or resource name describing the location of a script error
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     * causing the <code>ScriptException</code> to be thrown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     * @param lineNumber A line number describing the location of a script error causing
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     * the <code>ScriptException</code> to be thrown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    public ScriptException(String message, String fileName, int lineNumber) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        super(message);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        this.fileName = fileName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        this.lineNumber = lineNumber;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        this.columnNumber = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     * <code>ScriptException</code> constructor specifying message, filename, line number
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     * and column number.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     * @param message The message.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     * @param fileName The filename
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     * @param lineNumber the line number.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     * @param columnNumber the column number.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    public ScriptException(String message,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
            String fileName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
            int lineNumber,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
            int columnNumber) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        super(message);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        this.fileName = fileName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        this.lineNumber = lineNumber;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        this.columnNumber = columnNumber;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     * Returns a message containing the String passed to a constructor as well as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     * line and column numbers and filename if any of these are known.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     * @return The error message.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    public String getMessage() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        String ret = super.getMessage();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        if (fileName != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
            ret += (" in " + fileName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
            if (lineNumber != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
                ret += " at line number " + lineNumber;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
            if (columnNumber != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
                ret += " at column number " + columnNumber;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        return ret;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     * Get the line number on which an error occurred.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     * @return The line number.  Returns -1 if a line number is unavailable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    public int getLineNumber() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        return lineNumber;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * Get the column number on which an error occurred.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     * @return The column number.  Returns -1 if a column number is unavailable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    public int getColumnNumber() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        return columnNumber;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     * Get the source of the script causing the error.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     * @return The file name of the script or some other string describing the script
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     * source.  May return some implementation-defined string such as <i>&lt;unknown&gt;</i>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     * if a description of the source is unavailable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    public String getFileName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        return fileName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
}