Looking over my Raku code, I've realized that I pretty much never use CATCH blocks to actually catch/handle error. Instead, I handle errors with try blocks and testing for undefined values; the only thing I use CATCH blocks for is to log errors differently. I don't seem to be alone in this habit – looking at the CATCH blocks in the Raku docs, pretty much none of them handle the error in any sense beyond printing a message. (The …
如果一个 try{} 块中发生多个异常,并且该 try{} 块内只有一个 CATCH{} 块,那么该 CATCH{} 块是否可以捕获任何/所有异常?或者我是否需要针对每个可能的异常使用一个 CATCH{}?
try { CATCH { default { say "seenError" }; }; die "1"; die "2"; die "3" }
seenError
Run Code Online (Sandbox Code Playgroud)
在上面的例子中,哪个“die”语句被捕获了?第一?如果我想处理每个异常,是否需要将每个可能的异常包含在一个单独的 CATCH{} 中?