public String dumpStack() { StringBuilder buf = new StringBuilder(); buf.append("Traceback (most recent call last):\n"); dumpStack(buf); return buf.toString(); }
/** * Register frame as having been visited in the traceback. * * @param here the current PyFrame * @param isFinally whether caller is a Python finally block */ public void tracebackHere(PyFrame here, boolean isFinally) { if (!isReRaise && here != null) { // the frame is either inapplicable or already registered (from a finally) // during a re-raise traceback = new PyTraceback(traceback, here); } // finally blocks immediately tracebackHere: so they toggle isReRaise to skip the // next tracebackHere hook isReRaise = isFinally; }
private String tracebackInfo() { if (tb_frame == null || tb_frame.f_code == null) { return String.format(" (no code object) at line %s\n", tb_lineno); } String line = null; if (tb_frame.f_code.co_filename != null) { line = getLine(tb_frame.f_code.co_filename, tb_lineno); } return String.format(" File \"%.500s\", line %d, in %.500s\n%s", tb_frame.f_code.co_filename, tb_lineno, tb_frame.f_code.co_name, line == null ? "" : " " + line); }
public void dumpStack(StringBuilder buf) { buf.append(tracebackInfo()); if (tb_next != null && tb_next != this) { ((PyTraceback)tb_next).dumpStack(buf); } else if (tb_next == this) { buf.append("circularity detected!"+this+tb_next); } }
/** * We fix various following problems with PyTraceback.dumpStack() to make it * more suitable for incorporation with a Java stack trace. * <ul> * <li>PyTraceback doesn't use platform specific line separators.</li> * <li>Stacks are printed with the innermost frame last.</li> * <li>The indentation style is different.</li> * </ul> */ private static String tracebackToMessage(final String prefix, final PyTraceback traceback) { final StringBuilder result = new StringBuilder(prefix); if (traceback != null) { final String[] frames = traceback.dumpStack().split("\n"); for (int i = frames.length - 1; i >= 1; --i) { result.append(System.getProperty("line.separator")); result.append("\t"); result.append(frames[i].trim()); } } return result.toString(); } }
sb.append("\nMessage: ").append(errorMesage); sb.append("\nStack:\n"); pyException.traceback.dumpStack(sb); errorMsg = sb.toString();
stderr.print(((PyTraceback) tb).dumpStack());