Home

Published

- 1 min read

throw error in dart

img of throw error in dart

The solution for this is noted below

throw error in dart

Solution

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

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

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

Try other methods by searching on the site. That is if this doesn’t work