dart in try on catch

catch catch the exception

After capturing an exception, an exception to stop the capture process. Catch an exception, you have the opportunity to deal with it:

try {
  breedMoreLlamas();
} on OutOfLlamasException {
  buyMoreLlamas();
}

To handle multiple types of exceptions containing the code, you can select more catch clauses. The first match throwable type of catch clauses will handle the exception. If an exception type catch clause unspecified captured, this clause can handle any objects being thrown.

try {
  breedMoreLlamas();
} on OutOfLlamasException {
  // 一个具体异常
  buyMoreLlamas();
} on Exception catch (e) {
  // 任意一个异常
  print('Unknown exception: $e');
} catch (e) {
  // 非具体类型
  print('Something really unknown: $e');
}

Like the code shown above, you can use on or catch, or both. When you need to specify the type of exception when used on, when you need to exception handling exception object with the catch.

http://wiki.jikexueyuan.com/project/dart-language-tour/exceptions.html

Guess you like

Origin www.cnblogs.com/cag2050/p/10960185.html