Search
 
SCRIPT & CODE EXAMPLE
 

DART

dart custom exception

class CustomException implements Exception {
  String errorMessage() {
    return ("Invalid Amount");
  }
}

void AmountException(int amount) {
  if (amount <= 0) {
    throw new CustomException();
  }
}

void main() {
  try {
    AmountException(0);
  } catch (e) {
    print(errorMessage());
  }
}
Comment

dart custom exception

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');
}
Comment

PREVIOUS NEXT
Code Example
Dart :: what will do for each in dart 
Dart :: getters and setters dart 
Dart :: dart deep copy list 
Dart :: dispose in dart 
Dart :: android studio emulator blue screen windows 10 
Dart :: filterchip flutter 
Dart :: dart concat string and int 
Dart :: how to convert string into date format 
Dart :: listview flutter give padding to list bottom 
Dart :: dart promise all 
Dart :: flutter color hex 
Dart :: singleton classes in dart example 
Dart :: flutter create new map 
Dart :: dart flutter countdown timer 
Dart :: empty widget in flutter 
Dart :: flutter icon size 
Dart :: select date from datepicker in textfield flutter 
Dart :: vertically Center a Text in Flutter 
Dart :: Flutter how to get percentage of device height 
Dart :: align column to center of flex flutter 
Dart :: dart map clear 
Dart :: get current line number dart flutter 
Dart :: dart function syntax 
Dart :: with keyword in dart 
Dart :: how to use same bloc in multiple widgets in flutter 
Dart :: flutter add checkbox 
Dart :: dart set union 
Dart :: flutter app craches in android 12 
Dart :: Ascending order with for loop in dart 
Swift :: swift 5 delay dismiss view controller 
ADD CONTENT
Topic
Content
Source link
Name
7+9 =