gpt4 book ai didi

f# 处理多种异常类型的异常

转载 作者:行者123 更新时间:2023-12-05 01:15:04 24 4
gpt4 key购买 nike

我正在尝试根据 c# 中的异常类型捕获异常,但是当我执行以下操作时出现编译器错误This type test or downcast will always在线 | :? System.Exception as genericException ->F# 中不能有多个“catch”块吗?

try
......
with
| :? System.AggregateException as aggregateException ->
for innerException in aggregateException.InnerExceptions do
log message
| :? System.Exception as genericException ->
log message

最佳答案

因为:? System.Exception as是多余的,代码可以简化为:

try
// ...
with
| :? System.AggregateException as aggregateException ->
for innerException in aggregateException.InnerExceptions do
log message
| genericException -> log message

有关更多示例,请参阅此答案: How to catch any exception (System.Exception) without a warning in F#?

关于f# 处理多种异常类型的异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30256764/

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