2

In Scala I can generate an exception that carries a value of some type parameter A via case class MyException[A]( value: A ) extends Exception

Is there a way to define a similar type in F#?

exception MyException<'a> of 'a is not possible as far as I can see. Do I need to generate a separate exception for each type it should carry? I guess I could define a type T = INT int | BOOL bool | PAIR T * T and use it if I don't want to have multiple exceptions, but I'm wondering if there is a more elegant solution.

Matthias Schlaipfer
  • 510
  • 1
  • 3
  • 15
  • 1
    See also https://stackoverflow.com/questions/6099027/can-exception-types-be-generic – kvb Sep 05 '18 at 17:31

0 Answers0