Dart编程实例 - 抛出异常

本文为大家分享 Dart编程实例 - 抛出异常 的具体示例代码,提供大家参考,具体内容如下:

main() {
   try {
      test_age(-2);
   }

   catch(e) {
      print('Age cannot be negative');
   }
}  
void test_age(int age) {
   if(age<0) {
      throw new FormatException();
   }
}

本文为大家分享 Dart编程实例 - 自定义异常 的具体示例代码,提供大家参考,具体内容如下:class AmtException implements Exception { String errMsg( ...