contains method
Checks if this exception or any exception in its cause chain is of the specified type.
Example:
if (exception.contains(Class<ArgumentError>())) {
print('Contains an argument error in the chain');
}
Implementation
bool contains(Class? exType) {
if (exType == null) return false;
if (exType.isInstance(this)) return true;
Throwable? cause = getCause();
if (cause == this) return false;
if (cause is NestedCheckedException) {
return cause.contains(exType);
} else {
while (cause != null) {
if (exType.isInstance(cause)) return true;
if (cause.getCause() == cause) break;
if(cause.getCause() is Throwable) {
cause = cause.getCause() as Throwable;
} else {
break;
}
}
return false;
}
}