In Files

  • error.c
  • signal.c

Parent

Methods

SignalException

Attributes

signo[R]

Public Class Methods

new(sig) => signal_exception click to toggle source

Construct a new SignalException object. sig should be a known signal name, or a signal number.

 
               static VALUE
esignal_init(argc, argv, self)
    int argc;
    VALUE *argv;
    VALUE self;
{
    int argnum = 1;
    VALUE sig = Qnil;
    int signo;
    const char *signm;
    char tmpnm[(sizeof(int)*CHAR_BIT)/3+4];

    if (argc > 0) {
        sig = argv[0];
        if (FIXNUM_P(sig)) argnum = 2;
    }
    if (argc < 1 || argnum < argc) {
        rb_raise(rb_eArgError, "wrong number of arguments (%d for %d)",
                 argc, argnum);
    }
    if (argnum == 2) {
        signo = FIX2INT(sig);
        if (signo < 0 || signo > NSIG) {
            rb_raise(rb_eArgError, "invalid signal number (%d)", signo);
        }
        if (argc > 1) {
            sig = argv[1];
        }
        else {
            signm = signo2signm(signo);
            if (signm) {
                snprintf(tmpnm, sizeof(tmpnm), "SIG%s", signm);
            }
            else {
                snprintf(tmpnm, sizeof(tmpnm), "SIG%u", signo);
            }
            sig = rb_str_new2(signm = tmpnm);
        }
    }
    else {
        signm = SYMBOL_P(sig) ? rb_id2name(SYM2ID(sig)) : StringValuePtr(sig);
        if (strncmp(signm, "SIG", 3) == 0) signm += 3;
        signo = signm2signo(signm);
        if (!signo) {
            rb_raise(rb_eArgError, "unsupported name `SIG%s'", signm);
        }
        if (SYMBOL_P(sig)) {
            sig = rb_str_new2(signm);
        }
    }
    rb_call_super(1, &sig);
    rb_iv_set(self, "signo", INT2NUM(signo));

    return self;
}
            

Commenting is here to help enhance the documentation. For example, code samples, or clarification of the documentation.

If you have questions about Ruby or the documentation, please post to one of the Ruby mailing lists. You will get better, faster, help that way.

If you wish to post a correction of the docs, please do so, but also file bug report so that it can be corrected for the next release. Thank you.

If you want to help improve the Ruby documentation, please visit Documenting-ruby.org.

blog comments powered by Disqus