我试图根据c#中的异常类型捕获异常,但是当我执行以下操作时遇到编译器错误
第This type test or downcast will always
行的| :? System.Exception as genericException ->
你能不能拥有多个" catch" F#中的块?
try
......
with
| :? System.AggregateException as aggregateException ->
for innerException in aggregateException.InnerExceptions do
log message
| :? System.Exception as genericException ->
log message
答案 0 :(得分:2)
这是因为:? 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#?