A stack trace is used for debugging when an exception is thrown.

Java Code:
catch (Exception cause) {
    StackTraceElement elements[] = cause.getStackTrace();
    for (int i = 0, n = elements.length; i < n; i++) {       
        System.err.println(elements[i].getFileName() + ":" 
                      + elements[i].getLineNumber() 
                      + ">> " 
                      + elements[i].getMethodName() + "()");
    }
}