Throws / Rethrows
在观察FlatMap方法时,我们可以发现其函数声明
1 | public func flatMap(_ transform: (Element) throws -> String?) rethrows -> [String] |
根据StackOverflow的解释,其实只用看最后一句
1 | Roughly speaking, rethrows is for functions which do not throw errors "on their own", but only "forward" errors from their function parameters. |
以下两种函数的声明
1 | //该声明代表,入参lambda会丢出异常,函数本身throwCustomError也会丢出异常,内部会对lambda的异常进行处理 |
可以见比起Java的Throw更加细致,不知道是好还是坏,又加深了理解复杂度