Skip to content

Instantly share code, notes, and snippets.

@pietrocaselani
Created June 24, 2015 17:13
Show Gist options
  • Save pietrocaselani/ec35a2cc146f56b06f26 to your computer and use it in GitHub Desktop.
Save pietrocaselani/ec35a2cc146f56b06f26 to your computer and use it in GitHub Desktop.
DebugUtils
public static void printStackTrace(Throwable exception) {
if (DEBUG) {
String fullClassName = exception.getStackTrace()[2].getClassName();
String className = fullClassName.substring(fullClassName.lastIndexOf(".") + 1);
String methodName = exception.getStackTrace()[2].getMethodName();
int lineNumber = exception.getStackTrace()[2].getLineNumber();
Log.v("DebugUtils", className + "." + methodName + "():" + lineNumber + ":\nMessage:" + exception.getLocalizedMessage());
for (StackTraceElement stackTraceElement : exception.getStackTrace()) {
Log.e("DebugUtils", stackTraceElement.toString());
}
Log.e("DebugUtils", exception.toString());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment