Module 04 Β· Idioms, Errors & Gems β Lesson 3 of 6 Β· ~11 min
Errors: raise & rescue
raise β throwing on purpose
raise is Ruby's version of Swift's throw or Python's raise β you already know the shape. Give it an error class and a message:
raise ArgumentError, "minutes must be positive"
ArgumentError is one of many built-in error classes (TypeError, ZeroDivisionError, NoMethodError, and more) β pick the one that best describes what went wrong. Unhandled, raise crashes the program with that message and a backtrace, same as an uncaught exception in any language you know.