StackTrace is more than debuging

I’ve never think about what else StackTrace could do other than debuging, util I read this post.

public static String getCallingMethodInfo() {
final Throwable fakeException = new Throwable();
final StackTraceElement[] stackTrace = fakeException.getStackTrace();
if(stackTrace != null && stackTrace.length >= 2) {
StackTraceElement s = stackTrace[2];
if(s != null) {
return s.getClassName() + “.(” + s.getMethodName() +”):[“+ s.getLineNumber() + “] -:”; }
} return null;
}

Advertisements


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s