Catch multiple specific exception types in Dart with one catch expression

前端 未结 2 1414
南旧
南旧 2021-02-12 20:39

I know I can catch a specific Exception type in dart with the following:

try {
  ...
} on SpecificException catch(e) {
  ...
}

But is there a w

2条回答
  •  南方客
    南方客 (楼主)
    2021-02-12 20:49

    No, there isn't, but you can do this:

    try {
      ...
    } catch (e) {
      if (e is A || e is B {
        ...
      } else {
        rethrow;
      }
    }
    

提交回复
热议问题