Splits the stack trace into separate lines and extracts the template
name and line number.

@param t
@return  the separated stack trace lines
760164
private TeaStackTraceLine[] getTeaStackTraceLines(Throwable t) {

        // grab the existing stack trace
        StringWriter stackTraceGrabber = new StringWriter();
        t.printStackTrace(new PrintWriter(stackTraceGrabber));
        String stackTrace = stackTraceGrabber.toString();
        int extensionIndex = stackTrace.lastIndexOf(TEA_EXCEPTION);
        boolean isTeaException = extensionIndex != -1;
        if (isTeaException) {

            // trim off all lines after the last template exception
            int endIndex = stackTrace.indexOf('\n', extensionIndex);
            int endRIndex = stackTrace.indexOf('\r', extensionIndex);

            if(endRIndex>-1 && endRIndex<endIndex)
                endIndex=endRIndex;

            if (endIndex <= 0) {
                endIndex = stackTrace.length();
            }

            stackTrace = stackTrace.substring(0, endIndex);

            // parse each line
            List<TeaStackTraceLine> teaStackTraceLines =
                new ArrayList<TeaStackTraceLine>();
            StringTokenizer tokenizer = new StringTokenizer(stackTrace, "\n");
            while (tokenizer.hasMoreElements()) {
                String line = (String)tokenizer.nextElement();
                if (line.indexOf(TEA_EXCEPTION) != -1) {
                    /*
                    TODO: make sure this works for lines that don't have
                          line numbers.  Look in ESPN logs for examples.
                    at org.teatrove.teaservlet.template.schedule.substitute(schedule.tea:78)
                    at org.teatrove.teaservlet.template.shell.story.frame.substitute(shell/story/frame.tea)
                    */
                    String tempLine = line;

                    int bracket = tempLine.indexOf('(');
                    tempLine = tempLine.substring(bracket + 1);
                    bracket = tempLine.indexOf(')');
                    tempLine = tempLine.substring(0, bracket);
                    int colonIndex = tempLine.indexOf(':');
                    String templateName = null;
                    Integer lineNumber = null;
                    if (colonIndex >= 0) {
                        templateName = tempLine.substring(0, colonIndex);
                        try {
                            lineNumber = 
                                new Integer(tempLine.substring(colonIndex + 1));
                        }
                        catch (NumberFormatException nfe) { lineNumber = null; }
                    }
                    else {
                        templateName = tempLine;
                        lineNumber = null;
                    }
                    teaStackTraceLines.add(new TeaStackTraceLine(templateName,
                                                                 lineNumber,
                                                                 line));
                }
                else {
                    teaStackTraceLines.add(new TeaStackTraceLine(null, null, line));
                }
            }
            return (TeaStackTraceLine[]) teaStackTraceLines.toArray(
                              new TeaStackTraceLine[teaStackTraceLines.size()]);
        }
        else {
            return null;
        }
    }
1050870
static <T> T trace(Level level, Object reason) {
        // NOTE: do not make this method private as it affects stack traces
        try {
            if (System.getProperty(propertyName) != null) {
                StackTraceElement[] st = Thread.currentThread().getStackTrace();
                String method = "???";
                String cls = ToolProvider.class.getName();
                if (st.length > 2) {
                    StackTraceElement frame = st[2];
                    method = String.format((Locale)null, "%s(%s:%s)",
                                           frame.getMethodName(),
                                           frame.getFileName(),
                                           frame.getLineNumber());
                    cls = frame.getClassName();
                }
                Logger logger = Logger.getLogger(loggerName);
                if (reason instanceof Throwable) {
                    logger.logp(level, cls, method,
                                reason.getClass().getName(), (Throwable)reason);
                } else {
                    logger.logp(level, cls, method, String.valueOf(reason));
                }
            }
        } catch (SecurityException ex) {
            System.err.format((Locale)null, "%s: %s; %s%n",
                              ToolProvider.class.getName(),
                              reason,
                              ex.getLocalizedMessage());
        }
        return null;
    }
552500
public static String getRootStackTrace(Throwable t, int depth) {

		while(t.getCause() != null) {
			t = t.getCause();
		}
		return getStackTrace(t, depth, null);
	}
648197
public static String getExceptionLocation(Throwable t) {
       StackTraceElement element = findStackTraceElement(t);
       return element != null ? "(" + getSimpleClassName(element) + ":" + element.getLineNumber() + ")-" : "";
    }
234628
public static void printStackTrace(StackTraceElement[] trace, java.io.PrintStream out) {
        Strand.printStackTrace(trace, out);
    }
157923
private String printStackTrace(Object[] stackTrace) {
        StringBuilder output = new StringBuilder();
        for (Object line : stackTrace) {
            output.append(line);
            output.append(newline);
        }
        return output.toString();
    }
460555
public static Class<?> getExceptionCallerClass(final Throwable t) {
		final StackTraceElement[] stackTrace = t.getStackTrace();
		for (final StackTraceElement stackTraceElement : stackTrace) {
			logger.debug(stackTraceElement.getClassName().concat(".").concat(stackTraceElement.getMethodName()));
		}
		return null;
	}
899505
public static void printStackTrace(StackTraceElement[] trace, java.io.PrintWriter out) {
        Strand.printStackTrace(trace, out);
    }
401328
public static String getCaller() {
		Exception e = new Exception();
		StackTraceElement[] stack = e.getStackTrace();
		if (stack == null || stack.length < 2) return "?";
		// 0 is here, 1 is the caller of this method, 2 is its caller
		return stack[2].getClassName() + "#" + stack[2].getMethodName() + ":" + stack[2].getLineNumber();
	}
1061445
public static String getStackTrace(Throwable ex) {
        StringWriter buf = new StringWriter();
        ex.printStackTrace(new PrintWriter(buf));

        return buf.toString();
    }
232979
function parseStacktrace(e, scriptName) {
    var UNKNOWN_FUNCTION = '<unknown>';
    var node = /^\s*at (?:((?:\[object object\])?\S+(?: \[as \S+\])?) )?\(?(.*?):(\d+)(?::(\d+))?\)?\s*$/i;
    var lines = e.stacktrace.split('\n');
    var stack = [];
    var parts;
    var element;

    for (var i = 0, j = lines.length; i < j; ++i) {
        if ((parts = node.exec(lines[i]))) {
            element = {
                'file': parts[2],
                'method': parts[1] || UNKNOWN_FUNCTION,
                'line': parts[2] === scriptName ? +parts[3] - scriptContentLineOffset : +parts[3],
                'column': parts[4] ? +parts[4] : null
            };
        } else {
            continue;
        }
        stack.push(element);
    }

    return stack;
}
425707
public int getStackTraceDepth(Throwable throwable) {
    try {
      return (int) (Integer) getDepthMethod.invoke(javaLangAccess, throwable);
    } catch (InvocationTargetException e) {
      // There really should be no chance of runtime errors.
      if (e.getCause() instanceof RuntimeException) {
        throw (RuntimeException) e.getCause();
      } else if (e.getCause() instanceof Error) {
        throw (Error) e.getCause();
      }
      // This should not be possible because the getStackTraceElement() method does not declare
      // any checked exceptions (though APIs may change over time).
      throw new RuntimeException(e.getCause());
    } catch (IllegalAccessException e) {
      // This should never happen because the method has been successfully invoked once already.
      throw new AssertionError(e);
    }
  }
754072
private static StackTraceElementsFiller getStackTraceElementsFiller() {
		try {
			Method method = VMStack.class.getDeclaredMethod("fillStackTraceElements", Thread.class, StackTraceElement[].class);
			method.setAccessible(true);
			StackTraceElement[] trace = new StackTraceElement[STACK_TRACE_SIZE];
			method.invoke(null, Thread.currentThread(), trace);
			for (int i = 0; i < STACK_TRACE_SIZE; ++i) {
				StackTraceElement element = trace[i];
				if (element != null && AndroidRuntime.class.getName().equals(element.getClassName())
					&& "getStackTraceElementsFiller".equals(element.getMethodName())) {
					return new StackTraceElementsFiller(method, i);
				}
			}
			return new StackTraceElementsFiller(null, -1);
		} catch (NoClassDefFoundError error) {
			return new StackTraceElementsFiller(null, -1);
		} catch (Exception ex) {
			return new StackTraceElementsFiller(null, -1);
		}
	}
915415
private String filterStackTrace(String trace) {
    for (StackTraceFilter filter : stackFilters) {
      trace = filter.apply(trace);
    }
    return trace;
  }
28846
private static String getCallerFromTheCurrentStack() {
        StackTraceElement[] stes = new Throwable().getStackTrace();
        for (StackTraceElement ste : stes) {
            String stackLine = ste.toString();
            if (!stackLine.contains(LOG.class.getName())) {
                return stackLine;
            }
        }
        return stes[stes.length - 1].toString();
    }
929200
public static String toShortString(Throwable e, int stackLevel) {
        StackTraceElement[] traces = e.getStackTrace();
        StringBuilder sb = new StringBuilder(1024);
        sb.append(e.toString()).append("\t");
        if (traces != null) {
            for (int i = 0; i < traces.length; i++) {
                if (i < stackLevel) {
                    sb.append("\tat ").append(traces[i]).append("\t");
                } else {
                    break;
                }
            }
        }
        return sb.toString();
    }
933216
public static void trimStackTraceTo(Throwable t, Class<?> cls) {
    StackTraceElement[] ste = t.getStackTrace();
    String name = cls.getName();
    for (int i = 0; i < ste.length; i++) {
      if (ste[i].getClassName().equals(name)) {
        t.setStackTrace(Arrays.copyOf(ste, i));
        return;
      }
    }
  }