SignalException
SignalException类
Parent:Exception
收到信号时产生。
begin
Process.kill('HUP',Process.pid)
sleep # wait for receiver to handle signal sent by Process.kill
rescue SignalException => e
puts "received Exception #{e}"
end
produces:
received Exception SIGHUP
公共类方法
new(sig_name) → signal_exception Show source
new(sig_number , name) → signal_exception
构造一个新的SignalException对象。sig_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];
}
rb_check_arity(argc, 1, 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 {
sig = rb_signo2signm(signo
}
}
else {
int len = sizeof(signame_prefix
if (SYMBOL_P(sig)) sig = rb_sym2str(sig else StringValue(sig
signm = RSTRING_PTR(sig
if (strncmp(signm, signame_prefix, len) == 0) {
signm += len;
len = 0;
}
signo = signm2signo(signm
if (!signo) {
rb_raise(rb_eArgError, "unsupported name `%.*s%"PRIsVALUE"'",
len, signame_prefix, sig
}
sig = rb_sprintf("SIG%s", signm
}
rb_call_super(1, &sig
rb_ivar_set(self, id_signo, INT2NUM(signo)
return self;
}
公共实例方法
signo → num Show source
返回一个信号编号。
static VALUE
esignal_signo(VALUE self)
{
return rb_ivar_get(self, id_signo
}