Java - Throwable to Exception

Maik Klein picture Maik Klein · Sep 10, 2012 · Viewed 43.8k times · Source

I am currently using the play2 framework.

I have several classes which are throwing exceptions but play2s global onError handler uses throwable instead of an exception.

for example one of my classes is throwing a NoSessionException. Can I check a throwable object if it is a NoSessionException ?

Answer

kosa picture kosa · Sep 10, 2012

You can use instanceof to check it is of NoSessionException or not.

Example:

if (exp instanceof NoSessionException) {
...
}

Assuming exp is the Throwable reference.