Project

General

Profile

Ruby

Wiki

NoMemoryError
Raised when memory allocation fails.
ScriptError
ScriptError is the superclass for errors raised when a script can not be executed because of a +LoadError+, +NotImplementedError+ or a +SyntaxError+. Note these type of +ScriptErrors+ are not +StandardExceptions+ and will not be rescued unless it is specified explicitly (or its ancestor +Exception+).
LoadError
Raised when a file required (a Ruby script, extension library, ...) fails to load.

require 'this/file/does/not/exist' # => LoadError: no such file to load -- this/file/does/not/exist
NotImplementedError
Raised when a feature is not implemented on the current platform. For example, methods depending on the +fsync+ or +fork+ system calls may raise this exception if the underlying operating system or Ruby runtime does not support them.
SyntaxError
Raised when encountering Ruby code with an invalid syntax.

Interrupt
Raised with the interrupt signal is received, typically because the user pressed on Control-C (on most posix platforms). As such, it is a subclass of +SignalException+.

begin
puts "Press ctrl-C when you are bored"
loop {}
rescue Interrupt => e
puts "Note: You will typically use Signal.trap instead."
end
StandardError
The most standard error types are subclasses of StandardError. A rescue clause without an explicit Exception class will rescue all StandardErrors (and only those).

ArgumentError
Raised when the arguments are wrong and there isn't a more specific Exception class. For example, passing the wrong number of arguments or a value that is not acceptable will typically raise an ArgumentError.

[1, 2, 3].first(4, 5) # => ArgumentError: wrong number of arguments (2 for 1)
[1, 2, 3].first(-4) # => ArgumentError: negative array size
FiberError
Raised when an invalid operation is attempted on a Fiber, in particular when attempting to call/resume a dead fiber,attempting to yield from the root fiber, or calling a fiber across threads.

Note that some IO failures raise +SystemCallError+s and these are not subclasses of IOError:

File.open("does/not/exist") # => Errno::ENOENT: No such file or directory - does/not/exist
EOFError
Raised by some IO operations when reaching the end of file. Many IO methods exist in two forms,one that returns +nil+ when the end of file is reached, the other raises EOFError +EOFError+.+EOFError+ is a subclass of +IOError+.

puts foo # => NameError: undefined local variable or method `foo' for main:Object
Fixnum.const_set :answer, 42 # => NameError: wrong constant name answer
NoMethodError
Raised when a method is called on a receiver which doesn't have it defined and also fails to respond with +method_missing+.

"hello".to_ary # => NoMethodError: undefined method `to_ary' for "hello":String
RangeError
Raised when a given numerical value is out of range.

def me_myself_and_i
me_myself_and_i
end
me_myself_and_i # => SystemStackError: stack level too deep
Encoding::CompatibilityError
Raised by Encoding and String methods when the source encoding is incompatible with the target encoding.
Encoding::ConverterNotFoundError
Raised by transcoding methods when a named encoding does not correspond with a known converter.
Encoding::UndefinedConversionError
Raised by Encoding and String methods when a transcoding operation fails.
Encoding::InvalidByteSequenceError
Raised by Encoding and String methods when the string being transcoded contains a byte invalid for the either the source or target encoding.