method
full_message
ruby latest stable - Class:
Exception
full_message(p1 = {})public
Returns formatted string of exception . The returned string is formatted using the same format that Ruby uses when printing an uncaught exceptions to stderr.
If highlight is true the default error handler will send the messages to a tty.
order must be either of :top or :bottom, and places the error message and the innermost backtrace come at the top or the bottom.
The default values of these options depend on $stderr and its tty? at the timing of a call.
static VALUE
exc_full_message(int argc, VALUE *argv, VALUE exc)
{
VALUE opt, str, emesg, errat;
enum {kw_highlight, kw_order, kw_max_};
static ID kw[kw_max_];
VALUE args[kw_max_] = {Qnil, Qnil};
rb_scan_args(argc, argv, "0:", &opt);
if (!NIL_P(opt)) {
if (!kw[0]) {
#define INIT_KW(n) kw[kw_##n] = rb_intern_const(#n)
INIT_KW(highlight);
INIT_KW(order);
#undef INIT_KW
}
rb_get_kwargs(opt, kw, 0, kw_max_, args);
switch (args[kw_highlight]) {
default:
rb_raise(rb_eArgError, "expected true or false as "
"highlight: %+"PRIsVALUE, args[kw_highlight]);
case Qundef: args[kw_highlight] = Qnil; break;
case Qtrue: case Qfalse: case Qnil: break;
}
if (args[kw_order] == Qundef) {
args[kw_order] = Qnil;
}
else {
ID id = rb_check_id(&args[kw_order]);
if (id == id_bottom) args[kw_order] = Qtrue;
else if (id == id_top) args[kw_order] = Qfalse;
else {
rb_raise(rb_eArgError, "expected :top or :down as "
"order: %+"PRIsVALUE, args[kw_order]);
}
}
}
str = rb_str_new2("");
errat = rb_get_backtrace(exc);
emesg = rb_get_message(exc);
rb_error_write(exc, emesg, errat, str, args[kw_highlight], args[kw_order]);
return str;
}