Exception: Exception
Overview
Descendants of class Exception are used to communicate between raise methods 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. Programs may subclass Exception to add additional information.
Direct Known Subclasses
NoMemoryError, ScriptError, SecurityError, SignalException, StandardError, SystemExit, SystemStackError, fatal
Class Method Summary (collapse)
-
+ exception
call-seq:.
- + log_exceptions
- + log_exceptions=
Instance Method Summary (collapse)
-
- ==
Equality---If obj is not an Exception, returns false.
-
- backtrace
Returns any backtrace associated with the exception.
-
- exception
call-seq:.
-
- new
constructor
Construct a new Exception object, optionally passing in.
-
- inspect
Return this exception's class name an message.
-
- message
Returns the result of invoking exception.to_s.
-
- set_backtrace
Sets the backtrace information associated with exc.
-
- to_s
Returns exception's message (or the name of the exception if no message is set).
Constructor Details
Class Method Details
+ (Object) exception
call-seq:
exc.exception(string) -> an_exception or exc
With no argument, or if the argument is the same as the receiver, return the receiver. Otherwise, create a new exception object of the same class as the receiver, but with a message equal to string.to_str.
+ (Object) log_exceptions
+ (Object) log_exceptions=
Instance Method Details
- (Boolean) ==(obj)
Equality---If obj is not an Exception, returns false. Otherwise, returns true if exc and obj share same class, messages, and backtrace.
- (Array) backtrace
Returns any backtrace associated with the exception. The backtrace is an array of strings, each containing either "filename:lineNo: in `method"' or "filename:lineNo."
def a
raise "boom"
end
def b
a()
end
begin
b()
rescue => detail
print detail.backtrace.join("\n")
end
produces:
prog.rb:2:in `a'
prog.rb:6:in `b'
prog.rb:10
- (Object) exception
call-seq:
exc.exception(string) -> an_exception or exc
With no argument, or if the argument is the same as the receiver, return the receiver. Otherwise, create a new exception object of the same class as the receiver, but with a message equal to string.to_str.
- (String) inspect
Return this exception's class name an message
- (String) message
Returns the result of invoking exception.to_s. Normally this returns the exception's message or name. By supplying a to_str method, exceptions are agreeing to be used where Strings are expected.
- (Array) set_backtrace(array)
- (String) to_s
Returns exception's message (or the name of the exception if no message is set).