I am learning F# and I found an interesting question.
We can use F# type exception
exception MyExpetion of string
However, when we match it, we can use the same syntax as matching a discriminated union. At the same time, it is a System.Exception. How is this done? What is the type of F# exception? I tried to search but no clear answer is found. Thank you.
You can think of exception types as a sort of “open” discriminated union, where additional constructors for the
Exceptiontype can be added at any time. Therefore, as you might expect, the static type ofMyException "test"isException, and values of typeExceptioncan be matched against the patternMyException _.