Java examples for java.lang:Throwable
who Called Me via StackTraceElement
//package com.java2s; public class Main { public static String whoCalledMe() { StackTraceElement[] stackTraceElements = Thread.currentThread() .getStackTrace();/*from w ww. j a va 2 s . c o m*/ StackTraceElement caller = stackTraceElements[4]; String classname = caller.getClassName(); int idx = classname.lastIndexOf("."); if (idx > 0) classname = classname.substring(++idx); String methodName = caller.getMethodName(); // int lineNumber = caller.getLineNumber(); return classname + "." + methodName;// + ":" + lineNumber; } }