Check out example codes for "dart custom exception". It will help you in understanding the concepts better.

Code Example 1

class CustomException implements Exception {
  String cause;
  CustomException(this.cause);
}

void main() {
  try {
    throwException();
  } on CustomException {
    print("custom exception is been obtained");
  }
}

throwException() {
  throw new CustomException('This is my first custom exception');
}

Learn ReactJs, React Native from akashmittal.com