I just learned about Log.wtf
("What a Terrible Failure" lol) and I'm wondering when I should use it.
Log.wtf
with an exception and letting an exception go unhandled (crash)?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?
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
The difference is the exception is logged or not. The exception remains unhandled.
It doesn't affect crash reports.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With