How can I get the line number where the exception was thrown using Thread.UncaughtExceptionHandler?

Try

e.getStackTrace()[0].getLineNumber();

The first element in the stack trace is the most recently called method (the top of the call stack).

There are also methods to get the class, method and file name.

If the e you get in the UncaughtExceptionHandler does not work well for you (because it wraps the real exception), you can try e.getCause() and look at that stack trace.

Leave a Comment