gpt4 book ai didi

swift - 共享多种异常类型的异常处理代码

转载 作者:行者123 更新时间:2023-11-30 12:59:54 25 4
gpt4 key购买 nike

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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com