Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Log.wtf vs. Unhandled Exception

Tags:

android

I just learned about Log.wtf ("What a Terrible Failure" lol) and I'm wondering when I should use it.

  1. What is the difference between calling Log.wtf with an exception and letting an exception go unhandled (crash)?
  2. How does it affect crash reports in the Google Play Developer Console?
  3. I usually throw an IllegalStateException for unexpected conditions. Should I consider calling Log.wtf instead?

Edit:

See also: Under what circumstances will Android's Log.wtf terminate my app?

like image 691
cambunctious Avatar asked Sep 30 '16 17:09

cambunctious


1 Answers

What Log.wtf does is write the exception and its stack trace in the log, and only that. It neither catches nor throws exceptions. So

  1. The difference is the exception is logged or not. The exception remains unhandled.

  2. It doesn't affect crash reports.

  3. If you wish to log it, go ahead. But you'll want to keep throwing IllegalStateException.

EDIT

I tried debugging and stepping into Log.wtf but no luck.

What I've found is pretty much what is answered in the linked question. It seems that in the "default terrible failure handling" Log.wtf creates an internal exception (TerribleFailure) which wraps any given exception. Then it calls RuntimeInit.wtf(). Its javadoc says:

Report a serious error in the current process. May or may not cause the process to terminate (depends on system settings).

I guess the behavior of Log.wtf is up to the device manufacturer. My Sony C6503 doesn't seem to raise any exception or kill the process.

Some open source reference:

https://android.googlesource.com/platform/frameworks/base/+/master/core/java/android/util/Log.java

https://android.googlesource.com/platform/frameworks/base/+/master/core/java/com/android/internal/os/RuntimeInit.java

like image 98
nandsito Avatar answered Oct 22 '22 21:10

nandsito