Exceptions in Reason

Nik Graf
InstructorNik Graf
Share this video with your friends

Social Share Links

Send Tweet
Published 6 years ago
Updated 5 years ago

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.

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] [pause]

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

[00:31] [pause]

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

[00:48] [pause]

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.

egghead
egghead
~ 14 minutes ago

Member comments are a way for members to communicate, interact, and ask questions about a lesson.

The instructor or someone from the community might respond to your question Here are a few basic guidelines to commenting on egghead.io

Be on-Topic

Comments are for discussing a lesson. If you're having a general issue with the website functionality, please contact us at support@egghead.io.

Avoid meta-discussion

  • This was great!
  • This was horrible!
  • I didn't like this because it didn't match my skill level.
  • +1 It will likely be deleted as spam.

Code Problems?

Should be accompanied by code! Codesandbox or Stackblitz provide a way to share code and discuss it in context

Details and Context

Vague question? Vague answer. Any details and context you can provide will lure more interesting answers!

Markdown supported.
Become a member to join the discussionEnroll Today