summaryrefslogtreecommitdiff
path: root/error.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2001-07-02 08:46:28 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2001-07-02 08:46:28 +0000
commitffe1cf575ecd5f9215a75728947520e9e668fb8a (patch)
tree9536b7d2a0fae33e4e3a5b7cdccfac0bc0b04a4f /error.c
parentcc13bb43bcb1e6b6798bb3190eeb65494dd2d320 (diff)
* error.c (exc_exception): clone the receiver exception instead of
creating brand new exception object of the receiver. * eval.c (rb_eval_string_wrap): extend new ruby_top_self, not original self. * eval.c (rb_eval_cmd): respect ruby_wrapper if set. * eval.c (eval): do not update ruby_class unless scope is not provided. * eval.c (eval): preserve wrapper information. * eval.c (proc_invoke): ditto. * eval.c (block_pass): ditto. * parse.y (void_expr): too much warnings for void context (e.g. foo[1] that can be mere Proc call). * error.c (rb_name_error): new function to raise NameError with name attribute set. * eval.c (rb_f_missing): set name and args in the exception object. [new] * error.c (name_name): NameError#name - new method. * error.c (nometh_args): NoMethodError#args - new method. * lex.c (rb_reserved_word): lex_state after tRESCUE should be EXPR_MID. * gc.c (add_heap): allocation size of the heap unit is doubled for each allocation. * dir.c (isdelim): space, tab, and newline are no longer delimiters for glob patterns. * eval.c (svalue_to_avalue): new conversion scheme between single value and array values. * eval.c (avalue_to_svalue): ditto. * eval.c (rb_eval): REXPAND now uses avalue_to_svalue(), return and yield too. * eval.c (rb_yield_0): use avalue_to_svalue(). * eval.c (proc_invoke): Proc#call gives avaules, whereas Proc#yield gives mvalues. * eval.c (bmcall): convert given value (svalue) to avalue. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@1555 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'error.c')
-rw-r--r--error.c47
1 files changed, 41 insertions, 6 deletions
diff --git a/error.c b/error.c
index a2c3715..7f196ba 100644
--- a/error.c
+++ b/error.c
@@ -322,15 +322,11 @@ exc_exception(argc, argv, self)
VALUE *argv;
VALUE self;
{
- VALUE etype, exc;
+ VALUE exc;
if (argc == 0) return self;
if (argc == 1 && self == argv[0]) return self;
- etype = CLASS_OF(self);
- while (FL_TEST(etype, FL_SINGLETON)) {
- etype = RCLASS(etype)->super;
- }
- exc = rb_obj_alloc(etype);
+ exc = rb_obj_clone(self);
rb_obj_call_init(exc, argc, argv);
return exc;
@@ -417,6 +413,43 @@ exit_status(exc)
return rb_iv_get(exc, "status");
}
+void
+#ifdef HAVE_STDARG_PROTOTYPES
+rb_name_error(ID id, const char *fmt, ...)
+#else
+rb_name_error(id, fmt, va_alist)
+ ID id;
+ const char *fmt;
+ va_dcl
+#endif
+{
+ VALUE exc;
+
+ va_list args;
+ char buf[BUFSIZ];
+
+ va_init_list(args, fmt);
+ vsnprintf(buf, BUFSIZ, fmt, args);
+ va_end(args);
+ exc = rb_exc_new2(rb_eLoadError, buf);
+ rb_iv_set(exc, "name", ID2SYM(id));
+ rb_exc_raise(exc);
+}
+
+static VALUE
+name_name(self)
+ VALUE self;
+{
+ return rb_iv_get(self, "name");
+}
+
+static VALUE
+nometh_args(self)
+ VALUE self;
+{
+ return rb_iv_get(self, "args");
+}
+
#ifdef __BEOS__
typedef struct {
VALUE *list;
@@ -594,7 +627,9 @@ Init_Exception()
rb_eIndexError = rb_define_class("IndexError", rb_eStandardError);
rb_eRangeError = rb_define_class("RangeError", rb_eStandardError);
rb_eNameError = rb_define_class("NameError", rb_eStandardError);
+ rb_define_method(rb_eNameError, "name", name_name, 0);
rb_eNoMethodError = rb_define_class("NoMethodError", rb_eNameError);
+ rb_define_method(rb_eNoMethodError, "args", nometh_args, 0);
rb_eScriptError = rb_define_class("ScriptError", rb_eException);
rb_eSyntaxError = rb_define_class("SyntaxError", rb_eScriptError);