12 Days of Baddass Courses sale! Get instant access to the entire egghead library of courses and lessons for 58% off.

Runs out in:
05 : 09 : 47 : 02
Become a member
to unlock all features

    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.



    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




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

    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.

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

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

    Instructor: 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.