Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

public class Main {
    /**
     * Pass an exception to get back the stack trace
     * @param pException
     * @return stackTrace
     */
    public static String getStackTrace(Exception pException) {
        if (pException != null) {
            final StringBuilder strBuilder = new StringBuilder("Cause of error: ");
            strBuilder.append(pException.getMessage());
            strBuilder.append("\n");
            strBuilder.append(pException.toString());
            strBuilder.append("\n");
            final StackTraceElement[] elementArray = pException.getStackTrace();
            for (final StackTraceElement element : elementArray) {
                strBuilder.append(element.toString());
                strBuilder.append("\n");
            }
            return strBuilder.toString();
        } else {
            return null;
        }
    }
}