f# 处理多种异常类型的异常
f# handling exceptions for multiple exception types
我正在尝试像在 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#?
我正在尝试像在 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#?