Ruby Language Reference

raise method

Syntax

The raise method raises an exception.

raise exception_object, message

Exception Object and Message

For example:

raise Exception.new, 'Boom...'

This causes exception with the message 'Boom...':

Exception: Boom...

Exception Object

This causes the exception with the message 'Exception: Exception':

raise Exception.new

Message

This causes Runtime error exception with the message RuntimeError: Boom...:

raise 'Boom...'

No Exception Object, No Message

The raise method with no exception object raises message-less RuntimeError:

raise

Raise inside Rescue Clause

The raise without arguments in a rescue clause re-raises the exception:

begin
  raise 'Boom'
rescue
  raise
end

The output of this example is RuntimeError: Boom.


Sharing is Caring