Method: Exception#full_message
- Defined in:
- error.c
#full_message(highlight: true, order: :top) ⇒ String
Returns an enhanced message string:
-
Includes the exception class name.
-
If the value of keyword
highlight
is true (notnil
orfalse
), includes bolding ANSI codes (see below) to enhance the appearance of the message. -
Includes the backtrace:
-
If the value of keyword
order
is:top
(the default), lists the error message and the innermost backtrace entry first. -
If the value of keyword
order
is:bottom
, lists the error message the the innermost entry last.
-
Example:
def baz
begin
1 / 0
rescue => x
pp x.
pp x.(highlight: false).split("\n")
pp x..split("\n")
end
end
def ; baz; end
def foo; ; end
foo
Output:
"divided by 0"
["t.rb:3:in 'Integer#/': divided by 0 (ZeroDivisionError)",
"\tfrom t.rb:3:in 'Object#baz'",
"\tfrom t.rb:10:in 'Object#bar'",
"\tfrom t.rb:11:in 'Object#foo'",
"\tfrom t.rb:12:in '<main>'"]
["t.rb:3:in 'Integer#/': \e[1mdivided by 0 (\e[1;4mZeroDivisionError\e[m\e[1m)\e[m",
"\tfrom t.rb:3:in 'Object#baz'",
"\tfrom t.rb:10:in 'Object#bar'",
"\tfrom t.rb:11:in 'Object#foo'",
"\tfrom t.rb:12:in '<main>'"]
An overriding method should be careful with ANSI code enhancements; see Messages.
1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 |
# File 'error.c', line 1724
static VALUE
exc_full_message(int argc, VALUE *argv, VALUE exc)
{
VALUE opt, str, emesg, errat;
VALUE highlight, order;
rb_scan_args(argc, argv, "0:", &opt);
highlight = check_highlight_keyword(opt, 1);
order = check_order_keyword(opt);
{
if (NIL_P(opt)) opt = rb_hash_new();
rb_hash_aset(opt, sym_highlight, highlight);
}
str = rb_str_new2("");
errat = rb_get_backtrace(exc);
emesg = rb_get_detailed_message(exc, opt);
rb_error_write(exc, emesg, errat, str, opt, highlight, order);
return str;
}
|