0N/A/*
2362N/A * Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/Apackage javax.script;
0N/A
0N/A/**
0N/A * The generic <code>Exception</code> class for the Scripting APIs. Checked
0N/A * exception types thrown by underlying scripting implementations must be wrapped in instances of
0N/A * <code>ScriptException</code>. The class has members to store line and column numbers and
0N/A * filenames if this information is available.
0N/A *
0N/A * @author Mike Grogan
0N/A * @since 1.6
0N/A */
0N/Apublic class ScriptException extends Exception {
0N/A
0N/A private String fileName;
0N/A private int lineNumber;
0N/A private int columnNumber;
0N/A
0N/A /**
0N/A * Creates a <code>ScriptException</code> with a String to be used in its message.
0N/A * Filename, and line and column numbers are unspecified.
0N/A *
0N/A * @param s The String to use in the message.
0N/A */
0N/A public ScriptException(String s) {
0N/A super(s);
0N/A fileName = null;
0N/A lineNumber = -1;
0N/A columnNumber = -1;
0N/A }
0N/A
0N/A /**
0N/A * Creates a <code>ScriptException</code> wrapping an <code>Exception</code> thrown by an underlying
0N/A * interpreter. Line and column numbers and filename are unspecified.
0N/A *
0N/A * @param e The wrapped <code>Exception</code>.
0N/A */
0N/A public ScriptException(Exception e) {
0N/A super(e);
0N/A fileName = null;
0N/A lineNumber = -1;
0N/A columnNumber = -1;
0N/A }
0N/A
0N/A /**
0N/A * Creates a <code>ScriptException</code> with message, filename and linenumber to
0N/A * be used in error messages.
0N/A *
0N/A * @param message The string to use in the message
0N/A *
0N/A * @param fileName The file or resource name describing the location of a script error
0N/A * causing the <code>ScriptException</code> to be thrown.
0N/A *
0N/A * @param lineNumber A line number describing the location of a script error causing
0N/A * the <code>ScriptException</code> to be thrown.
0N/A */
0N/A public ScriptException(String message, String fileName, int lineNumber) {
0N/A super(message);
0N/A this.fileName = fileName;
0N/A this.lineNumber = lineNumber;
0N/A this.columnNumber = -1;
0N/A }
0N/A
0N/A /**
0N/A * <code>ScriptException</code> constructor specifying message, filename, line number
0N/A * and column number.
0N/A * @param message The message.
0N/A * @param fileName The filename
0N/A * @param lineNumber the line number.
0N/A * @param columnNumber the column number.
0N/A */
0N/A public ScriptException(String message,
0N/A String fileName,
0N/A int lineNumber,
0N/A int columnNumber) {
0N/A super(message);
0N/A this.fileName = fileName;
0N/A this.lineNumber = lineNumber;
0N/A this.columnNumber = columnNumber;
0N/A }
0N/A
0N/A /**
0N/A * Returns a message containing the String passed to a constructor as well as
0N/A * line and column numbers and filename if any of these are known.
0N/A * @return The error message.
0N/A */
0N/A public String getMessage() {
0N/A String ret = super.getMessage();
0N/A if (fileName != null) {
0N/A ret += (" in " + fileName);
0N/A if (lineNumber != -1) {
0N/A ret += " at line number " + lineNumber;
0N/A }
0N/A
0N/A if (columnNumber != -1) {
0N/A ret += " at column number " + columnNumber;
0N/A }
0N/A }
0N/A
0N/A return ret;
0N/A }
0N/A
0N/A /**
0N/A * Get the line number on which an error occurred.
0N/A * @return The line number. Returns -1 if a line number is unavailable.
0N/A */
0N/A public int getLineNumber() {
0N/A return lineNumber;
0N/A }
0N/A
0N/A /**
0N/A * Get the column number on which an error occurred.
0N/A * @return The column number. Returns -1 if a column number is unavailable.
0N/A */
0N/A public int getColumnNumber() {
0N/A return columnNumber;
0N/A }
0N/A
0N/A /**
0N/A * Get the source of the script causing the error.
0N/A * @return The file name of the script or some other string describing the script
0N/A * source. May return some implementation-defined string such as <i>&lt;unknown&gt;</i>
0N/A * if a description of the source is unavailable.
0N/A */
0N/A public String getFileName() {
0N/A return fileName;
0N/A }
0N/A}