Ahmad Raza Ahmad Raza - 1 year ago 111
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) ?

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download