Commit 75002290 authored by Yukihiro "Matz" Matsumoto's avatar Yukihiro "Matz" Matsumoto

Merge pull request #468 from iij/pr-exception-without-mesg

check if an Exception instance has a "mesg" attribute
parents 3a49dfd1 7a7f267b
...@@ -134,20 +134,23 @@ exc_inspect(mrb_state *mrb, mrb_value exc) ...@@ -134,20 +134,23 @@ exc_inspect(mrb_state *mrb, mrb_value exc)
mrb_str_cat2(mrb, str, ":"); mrb_str_cat2(mrb, str, ":");
mrb_str_append(mrb, str, line); mrb_str_append(mrb, str, line);
mrb_str_cat2(mrb, str, ": "); mrb_str_cat2(mrb, str, ": ");
if (RSTRING_LEN(mesg) > 0) { if (!mrb_nil_p(mesg) && RSTRING_LEN(mesg) > 0) {
mrb_str_append(mrb, str, mesg); mrb_str_append(mrb, str, mesg);
mrb_str_cat2(mrb, str, " ("); mrb_str_cat2(mrb, str, " (");
} }
mrb_str_cat2(mrb, str, mrb_obj_classname(mrb, exc)); mrb_str_cat2(mrb, str, mrb_obj_classname(mrb, exc));
if (RSTRING_LEN(mesg) > 0) { if (!mrb_nil_p(mesg) && RSTRING_LEN(mesg) > 0) {
mrb_str_cat2(mrb, str, ")"); mrb_str_cat2(mrb, str, ")");
} }
} }
else { else {
str = mrb_str_new2(mrb, mrb_obj_classname(mrb, exc)); str = mrb_str_new2(mrb, mrb_obj_classname(mrb, exc));
if (RSTRING_LEN(mesg) > 0) { if (!mrb_nil_p(mesg) && RSTRING_LEN(mesg) > 0) {
mrb_str_cat2(mrb, str, ": "); mrb_str_cat2(mrb, str, ": ");
mrb_str_append(mrb, str, mesg); mrb_str_append(mrb, str, mesg);
} else {
mrb_str_cat2(mrb, str, ": ");
mrb_str_cat2(mrb, str, mrb_obj_classname(mrb, exc));
} }
} }
return str; return str;
......
...@@ -269,3 +269,6 @@ assert('Exception 14') do ...@@ -269,3 +269,6 @@ assert('Exception 14') do
a == :ok a == :ok
end end
assert('Exception#inspect without message') do
Exception.new.inspect
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment