diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-02-24 07:39:59 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-02-24 07:39:59 +0000 |
commit | 7d742d47cc2f0023c4aeffdec6a6296f6c69a10f (patch) | |
tree | 1fdb32b8e245856dc4cec984b562b6c24e695aa3 /error.c | |
parent | 9acf2091e14e49949aab6f38e1a41dd3d7d3077e (diff) | |
download | ruby-7d742d47cc2f0023c4aeffdec6a6296f6c69a10f.tar.gz |
* error.c: new functions to deal exceptions with string instances.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@34787 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'error.c')
-rw-r--r-- | error.c | 48 |
1 files changed, 48 insertions, 0 deletions
@@ -1781,11 +1781,31 @@ make_errno_exc(const char *mesg) return rb_syserr_new(n, mesg); } +static VALUE +make_errno_exc_str(VALUE mesg) +{ + int n = errno; + + errno = 0; + if (!mesg) mesg = Qnil; + if (n == 0) { + const char *s = !NIL_P(mesg) ? RSTRING_PTR(mesg) : ""; + rb_bug("rb_sys_fail_str(%s) - errno == 0", s); + } + return rb_syserr_new_str(n, mesg); +} + VALUE rb_syserr_new(int n, const char *mesg) { VALUE arg; arg = mesg ? rb_str_new2(mesg) : Qnil; + return rb_syserr_new_str(n, arg); +} + +VALUE +rb_syserr_new_str(int n, VALUE arg) +{ return rb_class_new_instance(1, &arg, get_syserr(n)); } @@ -1796,12 +1816,24 @@ rb_syserr_fail(int e, const char *mesg) } void +rb_syserr_fail_str(int e, VALUE mesg) +{ + rb_exc_raise(rb_syserr_new_str(e, mesg)); +} + +void rb_sys_fail(const char *mesg) { rb_exc_raise(make_errno_exc(mesg)); } void +rb_sys_fail_str(VALUE mesg) +{ + rb_exc_raise(make_errno_exc_str(mesg)); +} + +void rb_mod_sys_fail(VALUE mod, const char *mesg) { VALUE exc = make_errno_exc(mesg); @@ -1810,6 +1842,14 @@ rb_mod_sys_fail(VALUE mod, const char *mesg) } void +rb_mod_sys_fail_str(VALUE mod, VALUE mesg) +{ + VALUE exc = make_errno_exc_str(mesg); + rb_extend_object(exc, mod); + rb_exc_raise(exc); +} + +void rb_mod_syserr_fail(VALUE mod, int e, const char *mesg) { VALUE exc = rb_syserr_new(e, mesg); @@ -1818,6 +1858,14 @@ rb_mod_syserr_fail(VALUE mod, int e, const char *mesg) } void +rb_mod_syserr_fail_str(VALUE mod, int e, VALUE mesg) +{ + VALUE exc = rb_syserr_new_str(e, mesg); + rb_extend_object(exc, mod); + rb_exc_raise(exc); +} + +void rb_sys_warning(const char *fmt, ...) { char buf[BUFSIZ]; |