If there is polymorphism such as checking SQLRecoverableException vs SQLException, it can be done like that.
try {
// sth may throw exception
....
} catch (Exception e) {
if(SQLException.class.isAssignableFrom(e.getCause().getClass()))
{
// do sth
System.out.println("SQLException occurs!");
}
}
Simply say,
ChildClass child= new ChildClass();
if(ParentClass.class.isAssignableFrom(child.getClass()))
{
// do sth
...
}