Example usage for java.lang Throwable Throwable

List of usage examples for java.lang Throwable Throwable

Introduction

In this page you can find the example usage for java.lang Throwable Throwable.

Prototype

public Throwable() 

Source Link

Document

Constructs a new throwable with null as its detail message.

Usage

From source file:Main.java

/**
 * Building Message/* w ww. j  a  v a  2s. c o  m*/
 * @param msg The message you would like logged.
 * @return Message String
 */
protected static String buildMessage(String msg) {
    StackTraceElement caller = new Throwable().fillInStackTrace().getStackTrace()[2];

    return caller.getClassName() + "." + caller.getMethodName() + "(): " + msg;
}

From source file:Main.java

public static void debug(Object message) {
    if (DEBUG) {//from w ww. j  av a2  s .c  o  m
        StackTraceElement element = new Throwable().getStackTrace()[1];
        print(element, message, null);
    }
}

From source file:Main.java

private static String getDebugInfo() {
    Throwable stack = new Throwable().fillInStackTrace();
    StackTraceElement[] trace = stack.getStackTrace();
    int n = 2;//from   w w w. jav a 2  s  .com
    return trace[n].getClassName() + " " + trace[n].getMethodName() + "()" + ":" + trace[n].getLineNumber()
            + " ";
}

From source file:Main.java

public static void log(Object message, Throwable error) {
    StackTraceElement element = new Throwable().getStackTrace()[1];
    print(element, message, error);//from   w ww  .  jav a 2 s  .co m
}

From source file:Main.java

public static String getLocation(int back) {
    try {/*from   w ww  .  ja  va  2 s.  c o m*/
        // Use Throwable to obtain stack trace, using Thread.currentThread().getStackTrace is expensive because of thread-safety */
        StackTraceElement e = (new Throwable()).getStackTrace()[back];
        if (e.isNativeMethod()) {
            return " [<native>]";
        }
        return " [" + e.getClassName().split("\\$")[0].replace('.', '/') + ".java:" + e.getLineNumber() + "]";
    } catch (ArrayIndexOutOfBoundsException e) {
    } catch (SecurityException e) {
    }
    return " [<unknown>]";
}

From source file:Main.java

public static void debug(Object message, Throwable error) {
    if (DEBUG) {/*from ww w  . j  av  a 2  s.  c  o  m*/
        StackTraceElement element = new Throwable().getStackTrace()[1];
        print(element, message, error);
    }
}

From source file:Main.java

public static StackTraceElement[] getStackTrace() {
    return new Throwable().fillInStackTrace().getStackTrace();
}

From source file:Main.java

private static String getMethod() {
    StackTraceElement[] stacks = new Throwable().getStackTrace();
    StackTraceElement currentStack = stacks[2];
    return currentStack.getMethodName();
}

From source file:Main.java

private static String generateTag() {
    StackTraceElement caller = new Throwable().getStackTrace()[2];
    String tag = "%s.%s(L:%d)";
    String callerClazzName = caller.getClassName();
    callerClazzName = callerClazzName.substring(callerClazzName.lastIndexOf(".") + 1);
    tag = String.format(tag, callerClazzName, caller.getMethodName(), caller.getLineNumber());
    tag = TextUtils.isEmpty(customTagPrefix) ? tag : customTagPrefix + ":" + tag;
    return tag;/*from w ww  .ja  va  2s  .co m*/
}

From source file:Main.java

private static String caller(int i) {
    StackTraceElement elem = new Throwable().getStackTrace()[i];
    return elem.getClassName() + "." + elem.getMethodName();
}