views:

94

answers:

2

I've written an unhandled error module for my iPhone app, but for some reason some errors are managing to bypass it.

I have an exception handler and the following signal handlers set:

NSSetUncaughtExceptionHandler(&handleException);
signal(SIGILL, handleSignal);
signal(SIGABRT, handleSignal);
signal(SIGFPE, handleSignal);
signal(SIGBUS, handleSignal);
signal(SIGSEGV, handleSignal);
signal(SIGSYS, handleSignal);
signal(SIGPIPE, handleSignal);

For most stuff (unrecognized selector, floating point errors, etc) it works, but for example when I run the following code:

NSString* str = [NSString stringWithFormat:@"a"];
[str release];
[str retain];

It avoids my error handler entirely and instead prints this to the console:

Stack dump: 0. Running pass 'Combine redundant instructions' on function '@glgRunProcessor10'**

I had another one that printed the following (but I can't remember what code I ran to cause it):

Stack dump: 0. Running pass 'Linear Scan Register Allocator' on function '@gldLLVMFPTransform5'

If I do this:

NSString* str = [NSString stringWithFormat:@"a"];
[str release];
[str init];

It doesn't print anything at all, but just exits the program.

Does anyone know of a surefire way to ensure that ALL errors get caught and run through a handler routine?

+1  A: 

I guess it depends on the SDK you are using.
I've tested the following code:

NSString * str = [ NSString stringWithFormat: @"a" ];
[ str release ];
[ str retain ];

With SDK 4.1, there's no error. It seems the runtime now allows that. It just prints a log to the console, but the app does not crash.

* __NSAutoreleaseFreedObject(): release of previously deallocated object (0x5f52fb0) ignored

With SDK 3.2, the signal handler is called (signal ID: 10).

So try to test that with different SDK versions. Hope this help...

Macmade
A: 

Well, it turns out that the exception handler IS getting called every time, but depending on the crash circumstances, stdout and stderr might already be closed by the time the error handler runs, which means the NSLog() messages won't get printed.

I confirmed by opening a file and dumping stuff to that instead.

Karl