Built-in Exceptions

Exception and the classes derived from it provide a variety of fundamental building blocks for handling error conditions in your Ruby scripts. Of course with the power you know and love from OOP, you can easily extend and adapt these basic classes as you see fit.

The following are abstract Exception classes:

Exception

Superclass of all exceptions

ScriptError

Error originating from program mistakes

StandardError

Superclass of standard error exceptions; caught if no class is specified by rescue

The following are subclasses of StandardError:

ArgumentError

Argument error (incorrect number of arguments, etc.)

EOFError

End of file reached

FloatDomainError

Float calculation error

IndexError

Error related to index.

IOError

Error related to input or output.

LocalJumpError

Error related to break, next, redo, retry, or return from wrong place.

NoMemoryError

Insufficient memory.

RangeError

Error produced when range exceeded

RegexpError

Regular expression error

RuntimeError

General runtime error

SecurityError

Error related to security

SystemCallError

Superclass of system call exceptions

SystemStackError

Insufficient stack area

TypeError

Error produced when types don’t match

ZeroDivisionError

Error produced when attempting to divide by zero

The following are two subclasses of SystemCallError. See <sys/errno.h> for details.

Errno::ENOENT

File or directory doesn’t exist

Errno::EPERM

Insufficient access rights

The following are subclasses of ScriptError:

LoadError

Error occurring during the loading of libraries

NameError ...

Get Ruby in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.