user5132301
user5132301

Reputation:

Check if an exception is a checked exception at runtime

Is this the correct way to check if an exception is a checked exception at runtime?

public boolean isChecked(final Throwable e) {
    return !(RuntimeException.class.isAssignableFrom(e.getClass()) 
             || Error.class.isAssignableFrom(e.getClass()));
}

Upvotes: 0

Views: 1731

Answers (1)

Steyrix
Steyrix

Reputation: 3226

I guess some condition like below will be enough

return !(e instanceof RuntimeException || e instanceof Error);

Upvotes: 2

Related Questions