Ahmad Raza Ahmad Raza - 6 months ago 42
Android Question

Throwable in log.e (String tag, String msg, Throwable tr)

I am reviewing android's code, saw log.e (String tag, String msg, Throwable tr) in code, but don't have any idea about 3rd parameter.
Please explain what is the functioning of 3rd parameter(Throwable tr) ?


java.lang.Throwable is something you can throw, for example an Exception.

The stacktrace of the throwable passed in the third arg will be logged as mentioned in the documentation.

is it possible that log.e(tag, msg, tr) throw exception, due to invalid tr(what if tr == null?)

Code where exceptions are logged are typically in catch blocks where the exception is not null. There can be a NPE "println needs a message" if msg is null though.