Catching system signals and exception handling
Catching system signals and exception handling
- Subject: Catching system signals and exception handling
- From: Aaron Burghardt <email@hidden>
- Date: Thu, 21 Jul 2005 11:03:38 -0400
Hi All,
I'm trying to learn how handle system signals so I can catch SIGBUS &
SIGSEGV signals, report them, and possibly recover from them. I've
tried using the NSExceptionHandler from the ExceptionHandling
framework, but I can't get it to catch signals and convert to
exceptions, so I've moved on to installing my own signal handler.
I would like to have my signal handler create and raise an
NSException. My test app will do it once, but subsequent signals get
caught in an infinite loop. Is there a way to do this? Do I need to
use setjmp/longjmp?
Thanks,
Aaron
Below is the condensed version of my test app.
- (void)awakeFromNib
{
initializeSignalHandler();
}
- (IBAction)generateBusError:(id)sender;
{
id myObject = 0x0A;
[myObject release];
}
void initializeSignalHandler( void )
{
NSLog(@"Registering signal handler");
signal( SIGBUS, handleSystemSignal);
}
void handleSystemSignal( int signal )
{
NSLog(@"Handling system signal");
NSException *exception = [NSException
exceptionWithName:@"BASystemSignalException"
reason:
[NSString stringWithFormat:@"Unhandled system signal: %i - %s",
signal, signalDescription[signal] ]
userInfo:
[NSDictionary dictionaryWithObjectsAndKeys:[NSNumber
numberWithInt:signal], @"Signal", nil]];
[exception raise];
}
Attachment:
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden