How can I get more detailed information about the exception that occurred in my application?

I want to show the details of an exception that occurred in my application, such as the line number of the exception. Is it possible?

+4
source share
5 answers

Yes. The following example contains a lot of information about your exception in stackTraceElement.

configure this method:

private static String getExceptionDetails(Activity act, Exception e) { StackTraceElement[] stackTraceElement = e.getStackTrace(); String fileName = ""; String methodName = ""; int lineNumber = 0; try { String packageName = act.getApplicationInfo().packageName; for (int i = 0; i < stackTraceElement.length; i++) { if (stackTraceElement[i].getClassName().startsWith(packageName)) { fileName = stackTraceElement[i].getFileName(); methodName = stackTraceElement[i].getMethodName(); lineNumber = stackTraceElement[i].getLineNumber(); break; } } } catch (Exception e2) { } return fileName + ":" + methodName + "():line " + String.valueOf(lineNumber); } 
+7
source

Have you checked it?

 exception.printStackTrace() 
+2
source
 exception.printStackTrace() 

Shows the line number and method name, throwing an exception.

+2
source

Use catch try block as

  try{ // here add your code }catch(Exception e){ Log.e("error",e.toString()); } 
0
source

check -

 exception.getMessage() 
-1
source

All Articles