The Exception Class
Information about an exception is encapsulated in an object of class Exception or in one of class Exception’s children. Ruby predefines a tidy hierarchy of exceptions, see https://docs.ruby-lang.org/en/master/Exception.html for the full list. As we’ll see later, this hierarchy makes handling exceptions considerably easier.
The most important subclass of Exception is StandardError. The StandardError exception and its subclasses represent the exceptional conditions that you’re going to want to capture in your code. Other subclasses of Exception are raised by Ruby internals or system-level problems. Almost all of the time, if you want to capture exceptions, you capture StandardError or one of its children.
When you need to ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access