In Files

Parent

Methods

SignalException

Raised when a signal is received.

begin
  Process.kill('HUP',Process.pid)
rescue SignalException => e
  puts "received Exception #{e}"
end

produces:

received Exception SIGHUP

Public Class Methods

new(sig_name) → signal_exception click to toggle source
new(sig_number [, name]) → signal_exception

Construct a new SignalException object. sig_name should be a known signal name.

 
               static VALUE
esignal_init(int argc, VALUE *argv, VALUE self)
{
    int argnum = 1;
    VALUE sig = Qnil;
    int signo;
    const char *signm;

    if (argc > 0) {
        sig = rb_check_to_integer(argv[0], "to_int");
        if (!NIL_P(sig)) argnum = 2;
        else sig = argv[0];
    }
    if (argc < 1 || argnum < argc) {
        rb_raise(rb_eArgError, "wrong number of arguments (%d for %d)",
                 argc, argnum);
    }
    if (argnum == 2) {
        signo = NUM2INT(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) {
                sig = rb_sprintf("SIG%s", signm);
            }
            else {
                sig = rb_sprintf("SIG%u", signo);
            }
        }
    }
    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);
        }
        sig = rb_sprintf("SIG%s", signm);
    }
    rb_call_super(1, &sig);
    rb_iv_set(self, "signo", INT2NUM(signo));

    return self;
}
            

Public Instance Methods

signo → num click to toggle source

Returns a signal number.

 
               static VALUE
esignal_signo(VALUE self)
{
    return rb_iv_get(self, "signo");
}
            

Commenting is here to help enhance the documentation. For example, sample code, 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.

blog comments powered by Disqus