“Pengecualian Kustom Dart” Kode Jawaban

Pengecualian Kustom Dart

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());
  }
}
Vivacious Vulture

Pengecualian Kustom Dart

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

Jawaban yang mirip dengan “Pengecualian Kustom Dart”

Pertanyaan yang mirip dengan “Pengecualian Kustom Dart”

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya