⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rhinoexception.java

📁 javascript语言的解释器源码
💻 JAVA
字号:
package org.mozilla.javascript;import java.io.CharArrayWriter;import java.io.PrintStream;import java.io.PrintWriter;/** * The class of exceptions thrown by the JavaScript engine. */public abstract class RhinoException extends RuntimeException{    RhinoException()    {        Interpreter.captureInterpreterStackInfo(this);    }    RhinoException(String details)    {        super(details);        Interpreter.captureInterpreterStackInfo(this);    }    public final String getMessage()    {        String details = details();        if (sourceName == null || lineNumber <= 0) {            return details;        }        StringBuffer buf = new StringBuffer(details);        buf.append(" (");        if (sourceName != null) {            buf.append(sourceName);        }        if (lineNumber > 0) {            buf.append('#');            buf.append(lineNumber);        }        buf.append(')');        return buf.toString();    }    public String details()    {        return super.getMessage();    }    /**     * Get the uri of the script source containing the error, or null     * if that information is not available.     */    public final String sourceName()    {        return sourceName;    }    /**     * Initialize the uri of the script source containing the error.     *     * @param sourceName the uri of the script source reponsible for the error.     *                   It should not be <tt>null</tt>.     *     * @throws IllegalStateException if the method is called more then once.     */    public final void initSourceName(String sourceName)    {        if (sourceName == null) throw new IllegalArgumentException();        if (this.sourceName != null) throw new IllegalStateException();        this.sourceName = sourceName;    }    /**     * Returns the line number of the statement causing the error,     * or zero if not available.     */    public final int lineNumber()    {        return lineNumber;    }    /**     * Initialize the line number of the script statement causing the error.     *     * @param lineNumber the line number in the script source.     *                   It should be positive number.     *     * @throws IllegalStateException if the method is called more then once.     */    public final void initLineNumber(int lineNumber)    {        if (lineNumber <= 0) throw new IllegalArgumentException(String.valueOf(lineNumber));        if (this.lineNumber > 0) throw new IllegalStateException();        this.lineNumber = lineNumber;    }    /**     * The column number of the location of the error, or zero if unknown.     */    public final int columnNumber()    {        return columnNumber;    }    /**     * Initialize the column number of the script statement causing the error.     *     * @param columnNumber the column number in the script source.     *                     It should be positive number.     *     * @throws IllegalStateException if the method is called more then once.     */    public final void initColumnNumber(int columnNumber)    {        if (columnNumber <= 0) throw new IllegalArgumentException(String.valueOf(columnNumber));        if (this.columnNumber > 0) throw new IllegalStateException();        this.columnNumber = columnNumber;    }    /**     * The source text of the line causing the error, or null if unknown.     */    public final String lineSource()    {        return lineSource;    }    /**     * Initialize the text of the source line containing the error.     *     * @param lineSource the text of the source line reponsible for the error.     *                   It should not be <tt>null</tt>.     *     * @throws IllegalStateException if the method is called more then once.     */    public final void initLineSource(String lineSource)    {        if (lineSource == null) throw new IllegalArgumentException();        if (this.lineSource != null) throw new IllegalStateException();        this.lineSource = lineSource;    }    final void recordErrorOrigin(String sourceName, int lineNumber,                                 String lineSource, int columnNumber)    {        // XXX: for compatibility allow for now -1 to mean 0        if (lineNumber == -1) {            lineNumber = 0;        }        if (sourceName != null) {            initSourceName(sourceName);        }        if (lineNumber != 0) {            initLineNumber(lineNumber);        }        if (lineSource != null) {            initLineSource(lineSource);        }        if (columnNumber != 0) {            initColumnNumber(columnNumber);        }    }    private String generateStackTrace()    {        // Get stable reference to work properly with concurrent access        CharArrayWriter writer = new CharArrayWriter();        super.printStackTrace(new PrintWriter(writer));        String origStackTrace = writer.toString();        return Interpreter.getPatchedStack(this, origStackTrace);    }    public void printStackTrace(PrintWriter s)    {        if (interpreterStackInfo == null) {            super.printStackTrace(s);        } else {            s.print(generateStackTrace());        }    }    public void printStackTrace(PrintStream s)    {        if (interpreterStackInfo == null) {            super.printStackTrace(s);        } else {            s.print(generateStackTrace());        }    }    private String sourceName;    private int lineNumber;    private String lineSource;    private int columnNumber;    Object interpreterStackInfo;    int[] interpreterLineData;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -