summaryrefslogtreecommitdiffhomepage
path: root/src/error.c
diff options
context:
space:
mode:
authorYukihiro "Matz" Matsumoto <[email protected]>2014-04-17 07:54:34 +0900
committerYukihiro "Matz" Matsumoto <[email protected]>2014-04-17 07:54:34 +0900
commitf756a8a72fc2856f54afc8f5da3d74299cdd5477 (patch)
tree0bc87a699d4d674e8965da03139dbf09d86f7b77 /src/error.c
parent26c0f8a77279d46cc19e21234581620a8a6bdb72 (diff)
parent36d3909e633e9dcf63f8f48c58bc8a59411c0544 (diff)
downloadmruby-f756a8a72fc2856f54afc8f5da3d74299cdd5477.tar.gz
mruby-f756a8a72fc2856f54afc8f5da3d74299cdd5477.zip
Merge pull request #2068 from cremno/exc_inspect-convert-mesg-to-string
convert exception message to string
Diffstat (limited to 'src/error.c')
-rw-r--r--src/error.c15
1 files changed, 10 insertions, 5 deletions
diff --git a/src/error.c b/src/error.c
index feec9dbc5..feaa61122 100644
--- a/src/error.c
+++ b/src/error.c
@@ -127,7 +127,12 @@ exc_inspect(mrb_state *mrb, mrb_value exc)
mesg = mrb_attr_get(mrb, exc, mrb_intern_lit(mrb, "mesg"));
file = mrb_attr_get(mrb, exc, mrb_intern_lit(mrb, "file"));
line = mrb_attr_get(mrb, exc, mrb_intern_lit(mrb, "line"));
- append_mesg = !mrb_nil_p(mesg) && RSTRING_LEN(mesg) > 0;
+
+ append_mesg = !mrb_nil_p(mesg);
+ if (append_mesg) {
+ mesg = mrb_obj_as_string(mrb, mesg);
+ append_mesg = RSTRING_LEN(mesg) > 0;
+ }
if (!mrb_nil_p(file) && !mrb_nil_p(line)) {
str = mrb_str_dup(mrb, file);
@@ -144,14 +149,14 @@ exc_inspect(mrb_state *mrb, mrb_value exc)
}
}
else {
- str = mrb_str_new_cstr(mrb, mrb_obj_classname(mrb, exc));
+ const char *cname = mrb_obj_classname(mrb, exc);
+ str = mrb_str_new_cstr(mrb, cname);
+ mrb_str_cat_lit(mrb, str, ": ");
if (append_mesg) {
- mrb_str_cat_lit(mrb, str, ": ");
mrb_str_append(mrb, str, mesg);
}
else {
- mrb_str_cat_lit(mrb, str, ": ");
- mrb_str_cat_cstr(mrb, str, mrb_obj_classname(mrb, exc));
+ mrb_str_cat_cstr(mrb, str, cname);
}
}
return str;