Type:
Class

Descendants of class Exception are used to communicate between Kernel#raise and rescue statements in begin ... end blocks. Exception objects carry information about the exception – its type (the exception's class name), an optional descriptive string, and optional traceback information. Exception subclasses may add additional information like NameError#name.

Programs may make subclasses of Exception, typically of StandardError or RuntimeError, to provide custom classes and add additional information. See the subclass list below for defaults for raise and rescue.

When an exception has been raised but not yet handled (in rescue, ensure, at_exit and END blocks) the global variable $! will contain the current exception and $@ contains the current exception's backtrace.

It is recommended that a library should have one subclass of StandardError or RuntimeError and have specific exception types inherit from it. This allows the user to rescue a generic exception type to catch all exceptions the library may raise even if future versions of the library add new exception subclasses.

For example:

class MyLibrary
  class Error < RuntimeError
  end

  class WidgetError < Error
  end

  class FrobError < Error
  end

end

To handle both WidgetError and FrobError the library user can rescue MyLibrary::Error.

The built-in subclasses of Exception are:

Exception serialization/deserialization

backtrace

exception.backtrace â array Instance Public methods Returns any backtrace

2015-04-05 13:48:05
as_json

as_json(*) Instance Public methods Returns a hash, that will be turned into

2015-04-05 13:45:06
exception

exc.exception(string) â an_exception or exc Class Public methods With no

2015-04-05 13:24:43
new

Exception.new(msg = nil) â exception Class Public methods Construct a new

2015-04-05 13:32:45
json_create

json_create(object) Class Public methods Deserializes

2015-04-05 13:28:08
to_json

to_json(*args) Instance Public methods Stores class name (Exception) with message

2015-04-05 14:11:38
message

exception.message â string Instance Public methods Returns the result of

2015-04-05 14:03:33
to_s

exception.to_s â string Instance Public methods Returns exception's message

2015-04-05 14:18:32
set_backtrace

exc.set_backtrace(backtrace) â array Instance Public methods Sets the backtrace

2015-04-05 14:07:47
exception 2

exc.exception(string) â an_exception or exc Instance Public methods With

2015-04-05 13:53:21