contains method

  1. @override
bool contains(
  1. Class? exType
)

Checks if this exception or any exception in its cause chain is of the specified type.

Example:

if (exception.contains(Class<IOException>())) {
  print('Contains an IO exception in the chain');
}

Implementation

@override
bool contains(Class? exType) {
  if (super.contains(exType)) {
    return true;
  }
  if (_relatedCauses != null) {
    for (var relatedCause in _relatedCauses) {
      if (relatedCause.getClass() == exType) {
        return true;
      }
      if (relatedCause is NestedRuntimeException &&
          relatedCause.contains(exType)) {
        return true;
      }
    }
  }
  return false;
}