diff options
author | shyouhei <shyouhei@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-12-12 00:46:34 +0000 |
---|---|---|
committer | shyouhei <shyouhei@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-12-12 00:46:34 +0000 |
commit | b57915eddc91ce0369ae8bcf82d8c4364f42ea05 (patch) | |
tree | c5296c8fd95c9ee041fe66455eb0744c3212b5c5 /error.c | |
parent | 0b31ce0047513d1eb8f9902286215025a3742bf5 (diff) |
Add FrozenError as a subclass of RuntimeError
FrozenError will be used instead of RuntimeError for exceptions
raised when there is an attempt to modify a frozen object. The
reason for this change is to differentiate exceptions related
to frozen objects from generic exceptions such as those generated
by Kernel#raise without an exception class.
From: Jeremy Evans <code@jeremyevans.net>
Signed-off-by: Urabe Shyouhei <shyouhei@ruby-lang.org>
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61131 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'error.c')
-rw-r--r-- | error.c | 19 |
1 files changed, 13 insertions, 6 deletions
@@ -804,6 +804,7 @@ VALUE rb_eSignal; VALUE rb_eFatal; VALUE rb_eStandardError; VALUE rb_eRuntimeError; +VALUE rb_eFrozenError; VALUE rb_eTypeError; VALUE rb_eArgError; VALUE rb_eIndexError; @@ -2011,16 +2012,21 @@ syserr_eqq(VALUE self, VALUE exc) */ /* - * Document-class: RuntimeError + * Document-class: FrozenError * - * A generic error class raised when an invalid operation is attempted. + * Raised when there is an attempt to modify a frozen object. * * [1, 2, 3].freeze << 4 * * <em>raises the exception:</em> * - * RuntimeError: can't modify frozen Array + * FrozenError: can't modify frozen Array + */ + +/* + * Document-class: RuntimeError * + * A generic error class raised when an invalid operation is attempted. * Kernel#raise will raise a RuntimeError if no Exception class is * specified. * @@ -2233,6 +2239,7 @@ Init_Exception(void) rb_define_method(rb_eNoMethodError, "private_call?", nometh_err_private_call_p, 0); rb_eRuntimeError = rb_define_class("RuntimeError", rb_eStandardError); + rb_eFrozenError = rb_define_class("FrozenError", rb_eRuntimeError); rb_eSecurityError = rb_define_class("SecurityError", rb_eException); rb_eNoMemError = rb_define_class("NoMemoryError", rb_eException); rb_eEncodingError = rb_define_class("EncodingError", rb_eStandardError); @@ -2588,7 +2595,7 @@ rb_load_fail(VALUE path, const char *err) void rb_error_frozen(const char *what) { - rb_raise(rb_eRuntimeError, "can't modify frozen %s", what); + rb_raise(rb_eFrozenError, "can't modify frozen %s", what); } void @@ -2601,11 +2608,11 @@ rb_error_frozen_object(VALUE frozen_obj) VALUE path = rb_ary_entry(debug_info, 0); VALUE line = rb_ary_entry(debug_info, 1); - rb_raise(rb_eRuntimeError, "can't modify frozen %"PRIsVALUE", created at %"PRIsVALUE":%"PRIsVALUE, + rb_raise(rb_eFrozenError, "can't modify frozen %"PRIsVALUE", created at %"PRIsVALUE":%"PRIsVALUE, CLASS_OF(frozen_obj), path, line); } else { - rb_raise(rb_eRuntimeError, "can't modify frozen %"PRIsVALUE, + rb_raise(rb_eFrozenError, "can't modify frozen %"PRIsVALUE, CLASS_OF(frozen_obj)); } } |