Pattern Match On Exceptions
ReasonML supports powerful pattern matching through the switch
statement. This even includes pattern matching against exceptions that may arise as a way of catching and handling those exceptions.
The List.nth
docs detail what happens in the two kinds of out of bounds scenarios that would raise an error -- Failure
and Invalid_argument
. You can pattern match against those by declaring the respective cases as exception instances and then returning the desired values in response.
Last updated