F # exception handling for multiple types of exceptions

I'm trying to catch exceptions based on the type of the exception, for example in C #, but I get a compiler error when I do the following: This type test or downcast will always

in line | :? System.Exception as genericException ->

Can you not have multiple catch blocks in F #?

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

      

+3


source to share


1 answer


This is because it :? System.Exception as

is redundant and the code can be summarized as follows:

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

      



See this answer for the following examples: How to catch any exception (System.Exception) without warning in F #?

+2


source







All Articles