diff options
author | tenderlove <tenderlove@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-03-06 23:38:33 +0000 |
---|---|---|
committer | tenderlove <tenderlove@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-03-06 23:38:33 +0000 |
commit | d576a25c26ea6765254e7ec247f951d6bb944703 (patch) | |
tree | 6d2dfbf2f25905f8927f04c9c21d93be796d2b08 /error.c | |
parent | c95cfa0a16305ffb2d701cb2f54bac8b501d86d5 (diff) | |
download | ruby-d576a25c26ea6765254e7ec247f951d6bb944703.tar.gz |
* error.c (rb_loaderror_with_path): Adding the missing file as an
instance variable to the LoadError exception.
* load.c: call rb_loaderror_with_path so that the missing path is
added to the exception.
* ruby.c: call rb_loaderror rather than raising our own LoadError
exception.
* include/ruby/intern.h: add declaration for rb_loaderror_with_path.
* test/ruby/test_require.rb: add supporting test for LoadError#path
method.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@34938 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'error.c')
-rw-r--r-- | error.c | 25 |
1 files changed, 23 insertions, 2 deletions
@@ -1691,7 +1691,10 @@ Init_Exception(void) rb_eScriptError = rb_define_class("ScriptError", rb_eException); rb_eSyntaxError = rb_define_class("SyntaxError", rb_eScriptError); + rb_eLoadError = rb_define_class("LoadError", rb_eScriptError); + rb_attr(rb_eLoadError, rb_intern("path"), 1, 0, Qfalse); + rb_eNotImpError = rb_define_class("NotImplementedError", rb_eScriptError); rb_eNameError = rb_define_class("NameError", rb_eStandardError); @@ -1742,11 +1745,29 @@ rb_loaderror(const char *fmt, ...) { va_list args; VALUE mesg; + VALUE err; + + va_start(args, fmt); + mesg = rb_enc_vsprintf(rb_locale_encoding(), fmt, args); + va_end(args); + err = rb_exc_new3(rb_eLoadError, mesg); + rb_ivar_set(err, rb_intern("@path"), Qnil); + rb_exc_raise(err); +} + +void +rb_loaderror_with_path(VALUE path, const char *fmt, ...) +{ + va_list args; + VALUE mesg; + VALUE err; va_start(args, fmt); mesg = rb_enc_vsprintf(rb_locale_encoding(), fmt, args); va_end(args); - rb_exc_raise(rb_exc_new3(rb_eLoadError, mesg)); + err = rb_exc_new3(rb_eLoadError, mesg); + rb_ivar_set(err, rb_intern("@path"), path); + rb_exc_raise(err); } void @@ -1889,7 +1910,7 @@ rb_sys_warning(const char *fmt, ...) void rb_load_fail(const char *path) { - rb_loaderror("%s -- %s", strerror(errno), path); + rb_loaderror_with_path(rb_str_new2(path), "%s -- %s", strerror(errno), path); } void |