Exception: Exception
Direct Known Subclasses
NoMemoryError, ScriptError, SignalException, StandardError, SystemExit, fatal
Class Method Summary collapse
-
.exception(string) ⇒ Exception
With no argument, or if the argument is the same as the receiver, return the receiver.
Instance Method Summary collapse
-
#backtrace ⇒ Array
Returns any backtrace associated with the exception.
-
#exception(string) ⇒ Exception
With no argument, or if the argument is the same as the receiver, return the receiver.
-
#new(msg = nil) ⇒ Exception
constructor
Construct a new Exception object, optionally passing in a message.
-
#inspect ⇒ String
Return this exception's class name an message.
-
#message ⇒ Object
Returns the result of invoking
exception.to_s
. -
#set_backtrace(array) ⇒ Array
Sets the backtrace information associated with exc.
-
#to_s ⇒ String
Returns exception's message (or the name of the exception if no message is set).
-
#to_str ⇒ Object
Returns the result of invoking
exception.to_s
.
Constructor Details
#new(msg = nil) ⇒ Exception
Construct a new Exception object, optionally passing in
a message.
|
# File 'error.c'
static VALUE
exc_initialize(argc, argv, exc)
int argc;
VALUE *argv;
VALUE exc;
{
VALUE arg;
rb_scan_args(argc, argv, "01", &arg);
rb_iv_set(exc, "mesg", arg);
rb_iv_set(exc, "bt", Qnil);
return exc;
}
|
Class Method Details
.exception(string) ⇒ Exception
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
.
Instance Method Details
#backtrace ⇒ Array
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
|
# File 'error.c'
static VALUE
exc_backtrace(exc)
VALUE exc;
{
static ID bt;
if (!bt) bt = rb_intern("bt");
return rb_attr_get(exc, bt);
}
|
#exception(string) ⇒ Exception
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
.
|
# File 'error.c'
/*
* Document-method: 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 <code>string.to_str</code>.
*
*/
static VALUE
exc_exception(argc, argv, self)
int argc;
VALUE *argv;
VALUE self;
{
VALUE exc;
if (argc == 0) return self;
if (argc == 1 && self == argv[0]) return self;
exc = rb_obj_clone(self);
exc_initialize(argc, argv, exc);
return exc;
}
|
#inspect ⇒ String
Return this exception's class name an message
|
# File 'error.c'
static VALUE
exc_inspect(exc)
VALUE exc;
{
VALUE str, klass;
klass = CLASS_OF(exc);
exc = rb_obj_as_string(exc);
if (RSTRING(exc)->len == 0) {
return rb_str_dup(rb_class_name(klass));
}
|
#message ⇒ String #to_str ⇒ String
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.
|
# File 'error.c'
static VALUE
exc_to_str(exc)
VALUE exc;
{
return rb_funcall(exc, rb_intern("to_s"), 0, 0);
}
|
#set_backtrace(array) ⇒ Array
Sets the backtrace information associated with exc. The argument must be an array of String
objects in the format described in Exception#backtrace
.
|
# File 'error.c'
static VALUE
exc_set_backtrace(exc, bt)
VALUE exc;
VALUE bt;
{
return rb_iv_set(exc, "bt", rb_check_backtrace(bt));
}
|
#to_s ⇒ String
Returns exception's message (or the name of the exception if no message is set).
|
# File 'error.c'
static VALUE
exc_to_s(exc)
VALUE exc;
{
VALUE mesg = rb_attr_get(exc, rb_intern("mesg"));
if (NIL_P(mesg)) return rb_class_name(CLASS_OF(exc));
if (OBJ_TAINTED(exc)) OBJ_TAINT(mesg);
return mesg;
}
|
#message ⇒ String #to_str ⇒ String
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.
|
# File 'error.c'
static VALUE
exc_to_str(exc)
VALUE exc;
{
return rb_funcall(exc, rb_intern("to_s"), 0, 0);
}
|