Become a member
to unlock all features

Level Up!

Access all courses & lessons on egghead today and lock-in your price for life.


    Exceptions in Reason


    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 Pro 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
    orLog In




    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.