summaryrefslogtreecommitdiff
path: root/error.c
diff options
context:
space:
mode:
Diffstat (limited to 'error.c')
-rw-r--r--error.c26
1 files changed, 22 insertions, 4 deletions
diff --git a/error.c b/error.c
index c28a855ea7..b6ab8c4959 100644
--- a/error.c
+++ b/error.c
@@ -554,15 +554,33 @@ exc_set_backtrace(VALUE exc, VALUE bt)
static VALUE
exc_equal(VALUE exc, VALUE obj)
{
+ VALUE mesg, backtrace;
ID id_mesg;
if (exc == obj) return Qtrue;
- if (rb_obj_class(exc) != rb_obj_class(obj))
- return Qfalse;
CONST_ID(id_mesg, "mesg");
- if (!rb_equal(rb_attr_get(exc, id_mesg), rb_attr_get(obj, id_mesg)))
+
+ if (rb_obj_class(exc) != rb_obj_class(obj)) {
+ ID id_message, id_backtrace;
+ CONST_ID(id_message, "message");
+ CONST_ID(id_backtrace, "backtrace");
+
+ if (rb_respond_to(obj, id_message) && rb_respond_to(obj, id_backtrace)) {
+ mesg = rb_funcall(obj, id_message, 0, 0);
+ backtrace = rb_funcall(obj, id_backtrace, 0, 0);
+ }
+ else {
+ return Qfalse;
+ }
+ }
+ else {
+ mesg = rb_attr_get(obj, id_mesg);
+ backtrace = exc_backtrace(obj);
+ }
+
+ if (!rb_equal(rb_attr_get(exc, id_mesg), mesg))
return Qfalse;
- if (!rb_equal(exc_backtrace(exc), exc_backtrace(obj)))
+ if (!rb_equal(exc_backtrace(exc), backtrace))
return Qfalse;
return Qtrue;
}