Here you can find the source of stackTraceToString(Exception e, int nBack)
public static String stackTraceToString(Exception e, int nBack)
//package com.java2s; public class Main { public static String stackTraceToString(Exception e, int nBack) { return stackTraceToString(e.getStackTrace(), nBack); }// w ww.j av a2 s. c om public static String stackTraceToString(StackTraceElement[] trace, int nBack) { int index = 0; if (trace.length < (index + 1)) { return "n/a"; } StringBuilder sb = new StringBuilder("trace..."); while (index < trace.length) { StackTraceElement elem = trace[index]; sb.append(String.format("%n%s.%s line %s", elem.getClassName(), elem.getMethodName(), elem.getLineNumber())); nBack--; if (nBack <= 0) { break; } index++; } return sb.toString(); } }