src/jdk/nashorn/api/scripting/NashornException.java

Print this page




 155                 if (methodName.equals(CompilerConstants.RUN_SCRIPT.symbolName())) {
 156                     methodName = "<program>";
 157                 }
 158                 filtered.add(new StackTraceElement(className, methodName,
 159                         st.getFileName(), st.getLineNumber()));
 160             }
 161         }
 162         return filtered.toArray(new StackTraceElement[filtered.size()]);
 163     }
 164 
 165     /**
 166      * Return a formatted script stack trace string with frames information separated by '\n'
 167      *
 168      * @param exception exception for which script stack string is returned
 169      * @return formatted stack trace string
 170      */
 171     public static String getScriptStackString(final Throwable exception) {
 172         final StringBuilder buf = new StringBuilder();
 173         final StackTraceElement[] frames = getScriptFrames((Throwable)exception);
 174         for (final StackTraceElement st : frames) {

 175             buf.append(st.getMethodName());
 176             buf.append(" @ ");
 177             buf.append(st.getFileName());
 178             buf.append(':');
 179             buf.append(st.getLineNumber());
 180             buf.append('\n');
 181         }
 182         final int len = buf.length();
 183         // remove trailing '\n'
 184         if (len > 0) {
 185             assert buf.charAt(len - 1) == '\n';
 186             buf.deleteCharAt(len - 1);
 187         }
 188         return buf.toString();
 189     }
 190 }


 155                 if (methodName.equals(CompilerConstants.RUN_SCRIPT.symbolName())) {
 156                     methodName = "<program>";
 157                 }
 158                 filtered.add(new StackTraceElement(className, methodName,
 159                         st.getFileName(), st.getLineNumber()));
 160             }
 161         }
 162         return filtered.toArray(new StackTraceElement[filtered.size()]);
 163     }
 164 
 165     /**
 166      * Return a formatted script stack trace string with frames information separated by '\n'
 167      *
 168      * @param exception exception for which script stack string is returned
 169      * @return formatted stack trace string
 170      */
 171     public static String getScriptStackString(final Throwable exception) {
 172         final StringBuilder buf = new StringBuilder();
 173         final StackTraceElement[] frames = getScriptFrames((Throwable)exception);
 174         for (final StackTraceElement st : frames) {
 175             buf.append("\tat ");
 176             buf.append(st.getMethodName());
 177             buf.append(" (");
 178             buf.append(st.getFileName());
 179             buf.append(':');
 180             buf.append(st.getLineNumber());
 181             buf.append(")\n");
 182         }
 183         final int len = buf.length();
 184         // remove trailing '\n'
 185         if (len > 0) {
 186             assert buf.charAt(len - 1) == '\n';
 187             buf.deleteCharAt(len - 1);
 188         }
 189         return buf.toString();
 190     }
 191 }