Search in sources :

Example 1 with WrappedException

use of net.sourceforge.htmlunit.corejs.javascript.WrappedException in project htmlunit by HtmlUnit.

the class ScriptException method createPrintableStackTrace.

private String createPrintableStackTrace() {
    final StringWriter stringWriter = new StringWriter();
    final PrintWriter printWriter = new PrintWriter(stringWriter);
    printWriter.println("======= EXCEPTION START ========");
    if (getCause() != null) {
        if (getCause() instanceof EcmaError) {
            final EcmaError ecmaError = (EcmaError) getCause();
            printWriter.print("EcmaError: ");
            printWriter.print("lineNumber=[");
            printWriter.print(ecmaError.lineNumber());
            printWriter.print("] column=[");
            printWriter.print(ecmaError.columnNumber());
            printWriter.print("] lineSource=[");
            printWriter.print(getFailingLine());
            printWriter.print("] name=[");
            printWriter.print(ecmaError.getName());
            printWriter.print("] sourceName=[");
            printWriter.print(ecmaError.sourceName());
            printWriter.print("] message=[");
            printWriter.print(ecmaError.getMessage());
            printWriter.print("]");
            printWriter.println();
        } else {
            printWriter.println("Exception class=[" + getCause().getClass().getName() + "]");
        }
    }
    super.printStackTrace(printWriter);
    if (getCause() instanceof JavaScriptException) {
        final Object value = ((JavaScriptException) getCause()).getValue();
        printWriter.print("JavaScriptException value = ");
        if (value instanceof Throwable) {
            ((Throwable) value).printStackTrace(printWriter);
        } else {
            printWriter.println(value);
        }
    } else if (getCause() instanceof WrappedException) {
        final WrappedException wrappedException = (WrappedException) getCause();
        printWriter.print("WrappedException: ");
        wrappedException.printStackTrace(printWriter);
        final Throwable innerException = wrappedException.getWrappedException();
        if (innerException == null) {
            printWriter.println("Inside wrapped exception: null");
        } else {
            printWriter.println("Inside wrapped exception:");
            innerException.printStackTrace(printWriter);
        }
    } else if (getCause() != null) {
        printWriter.println("Enclosed exception: ");
        getCause().printStackTrace(printWriter);
    }
    if (scriptSourceCode_ != null && !scriptSourceCode_.isEmpty()) {
        printWriter.println("== CALLING JAVASCRIPT ==");
        printWriter.println(scriptSourceCode_);
    }
    printWriter.println("======= EXCEPTION END ========");
    return stringWriter.toString();
}
Also used : WrappedException(net.sourceforge.htmlunit.corejs.javascript.WrappedException) EcmaError(net.sourceforge.htmlunit.corejs.javascript.EcmaError) StringWriter(java.io.StringWriter) PrintWriter(java.io.PrintWriter) JavaScriptException(net.sourceforge.htmlunit.corejs.javascript.JavaScriptException)

Aggregations

PrintWriter (java.io.PrintWriter)1 StringWriter (java.io.StringWriter)1 EcmaError (net.sourceforge.htmlunit.corejs.javascript.EcmaError)1 JavaScriptException (net.sourceforge.htmlunit.corejs.javascript.JavaScriptException)1 WrappedException (net.sourceforge.htmlunit.corejs.javascript.WrappedException)1