PHP 7.1 引入了一种针对多种异常类型重用异常处理代码的方法。
https://wiki.php.net/rfc/multiple-catch
<?php
try {
// Some code...
} catch (ExceptionType1 | ExceptionType2 $e) {
// Code to handle the exception
} catch (\Exception $e) {
// ...
}
Swift 3 是否提供类似的方式,例如在 catch 表达式中使用 where 子句?
最佳答案
你可以试试这个:
catch let error where error is ErrorType1 || error is ErrorType2
关于swift - 共享多种异常类型的异常处理代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39973561/