“Lempar kesalahan di panah” Kode Jawaban

pengecualian panah

try {
  breedMoreLlamas();
} on OutOfLlamasException {			// A specific exception  
  buyMoreLlamas();
} on Exception catch (e) { 			// Anything else that is an exception
  print('Unknown exception: $e');
} catch (e) {						// No specified type, handles all
  print('Something really unknown: $e');
} finally {							// Always clean up, even if case of exception
  cleanLlamaStalls();
}
VasteMonde

Lempar kesalahan di panah

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

Jawaban yang mirip dengan “Lempar kesalahan di panah”

Pertanyaan yang mirip dengan “Lempar kesalahan di panah”

Lebih banyak jawaban terkait untuk “Lempar kesalahan di panah” di Dart

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya