In addition to checking if its an instanceof you can use the try catch and catch NoSessionException
try {
// Something that throws a throwable
} catch (NoSessionException e) {
// Its a NoSessionException
} catch (Throwable t) {
// catch all other Throwables
}