Java tutorial
//package com.java2s; public class Main { public static String convertStackTraceToString(StackTraceElement[] stackTraceElements) { StringBuilder message = new StringBuilder(); int min = Math.min(stackTraceElements.length, 4); for (int i = 2; i < min; i++) { StackTraceElement element = stackTraceElements[i]; message.append(element.getClassName()).append(": ").append(element.getMethodName()).append("\n"); } return message.toString(); } }