An exception is raised with a codice_23 call:

An optional message can be added to the exception:

Exceptions can also be specified by the programmer:

Alternatively, an exception instance can be passed to the codice_23 method:

This last construct is useful when a custom exception class featuring a constructor which takes more than one argument needs to be raised:

Exceptions are handled by the codice_25 clause. Such a clause can catch exceptions which inherit from codice_26. Other flow control keywords that can be used when handling exceptions are codice_27 and codice_28:

It is a common mistake to attempt to catch all exceptions with a simple rescue clause. To catch all exceptions one must write:

Or catch particular exceptions:

It is also possible to specify that the exception object be made available to the handler clause:

Alternatively, the most recent exception is stored in the magic global codice_29.

Several exceptions can also be caught:

Metaprogramming
ଉଦାହରଣ
Exceptions
ବାହାର ଲିଙ୍କ