0

I'm writing a custom exception handler that basically reports every crash of an application and i want to get logcat output after an exception occurs. That's the easy part, i just use

Runtime.getRuntime().exec("logcat -d");

But that only gives me all of the logcat that occured prior to the exception, e.g. i dont get the FATAL part of the exception. So if my app crashes two times i will get the first FATAL signal in the second crash.

Is there a way around this? Using a Thread.sleep is not really an option, unless the sleep is really small, but that seems kind-of hackish...

Squeazer
  • 1,234
  • 1
  • 14
  • 33
  • or printStackTrace() dosent work? – Soumil Deshpande May 28 '14 at 12:10
  • Personally I just put try/catch blocks around any bit of code which might throw an exception including multiple catch blocks where necessary as well as a final generic catch for `Exception`. In all of them I either compensate or retry operations or I simply use `e.prinStackTrace` to indicate what went wrong. – Squonk May 28 '14 at 12:24

1 Answers1

1

Is there a way around this?

Capture the stack trace of the Exception that you caught.

Community
  • 1
  • 1
CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • I'm already doing this, but i would also like it to appear in the logcat output (so there wouldn't be any confusion when dealing with multiple crashes). – Squeazer May 28 '14 at 12:18
  • @Squeazer: Well, by definition, it will not appear in the LogCat output until after you allow it to appear in the LogCat output, by re-throwing the exception or otherwise allowing the default exception handling logic to appear. – CommonsWare May 28 '14 at 12:23
  • But if i, for instance, use my custom `UncaughtExceptionHandler`, and get the logcat as i described above, then after the crash i capture the logcat through adb it will appear there. Is there any way i can get that inside my handler or does the app have to exit / the handler has to finish before it writes the exception to logcat? – Squeazer May 28 '14 at 13:11
  • @Squeazer: "Is there any way i can get that inside my handler" -- no. "does the app have to exit / the handler has to finish before it writes the exception to logcat?" -- yes. – CommonsWare May 28 '14 at 13:12
  • well that sucks. Thanks for the help! – Squeazer May 28 '14 at 13:12