Autoplay

    Exceptions in Reason

    Nik GrafNik Graf

    While it's not recommend to make extensive use of exceptions in ReasonML, it's still worth introducing them. In this lesson we walk through how to create, raise and catch them.

    reasonReason
    Code

    Code

    Become a Member to view code

    You must be a Member to view code

    Access all courses and lessons, track your progress, gain confidence and expertise.

    Become a Member
    and unlock code for this lesson
    Transcript

    Transcript

    Instructor: 00:00 Reason also has exceptions. For example, if you try to find the integer 42 inside an empty list, an exception, not found, is thrown.

    00:09 We also can raise our own exceptions using the raise function. To catch them, we can use pattern matching, since exceptions are just a special kind of variant.

    00:20

    Instructor: 00:25 In fact, we can directly match exceptions, as well, in a switch expression using the exception keyword.

    00:31

    Instructor: 00:45 Using the exception keyword, we can also create an exception.

    00:48

    Instructor: 00:55 In general, it's recommended to use exceptions sparingly. In most cases, you get away just fine using an option. Also, more and more often, newer APIs are doing so.

    Discuss

    Discuss