Try Catch Doesn't Work - objective-c

I'm getting this stack trace in the output window of XCode 4:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[Page bottom]: unrecognized selector sent to instance 0xfbdb1f0'
However, the calling code has a try catch
#try {
[self restoreStateWithControlSurfaces:result];
}
#catch (NSException *exception) {
NSLog(#"Failed at restoreStateWithControlSurfaces %#", exception);
retVal = NO;
}
It might have something to do with NSHangOnOtherExceptionMask but I'm not sure how this fits together. How can I get my catch block to work? This is in the simulator for iPad 4.2.

A bug has been reported that prevents NSInvalidArgumentException from being caught. This bug appears to affect the simulator only.

Related

Gimbal Geofence monitoring crashing NSInvalidArgumentException -[NSURL initFileURLWithPath:]

After integrating Gimbal FYX beacon discovery I tried to add Geofence monitoring as well. I've follow the guides closely and re-written the code several times, ending up with the same crash and error message:
* Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '* -[NSURL initFileURLWithPath:]: nil string parameter'
Nowhere in my code am I accessing any files or creating any NSObjects from initWithContentsOfFile: methods!
My Code:
[connector enableFromViewController:viewController success:^{
NSLog(#"ContextCoreConnector ACTIVATED!");
self.placeConnector = [[QLContextPlaceConnector alloc] init];
self.placeConnector.delegate = self;
[self.placeConnector monitorPlacesWhenAllowed];
[self.placeConnector monitorPlacesInBackground];
if ([self.geofenceDelegate respondsToSelector:#selector(startedGeofenceMonitoring)]) {
[self.geofenceDelegate startedGeofenceMonitoring];
}
} failure:^(NSError *error) {
NSLog(#"ContextCoreConnector FAILED!\n%#",error.localizedDescription);
if ([self.geofenceDelegate respondsToSelector:#selector(startedGeofenceMonitoring)]) {
[self.geofenceDelegate startedGeofenceMonitoring];
}
}];
Turns out in the ContextLocation.framework there is a folder called "Resources" and there is a DataModels.bundle file that you need to check the 'Target Membership' in the right side panel of XCode. I had checked all my frameworks as the guides suggested but not that Resources folder.

NSKeyedUnarchiver unarchiveObjectWithData crashes - No way to catch the exception?

I have the following code:
#try {
NSSet *set = [NSKeyedUnarchiver unarchiveObjectWithData:mData];
}
#catch (NSException *exception) {
// Use default data
}
At some point it seems that I wasn't archiving properly and mData is corrupted.
This gives me the following error:
Terminating app due to uncaught exception 'NSInvalidArgumentException',
reason: '*** -[NSKeyedUnarchiver initForReadingWithData:]:
incomprehensible archive (0x14, 0xffffff9a, 0xffffffd0, 0x1d, 0x9, 0x3d, 0x43, 0x3)'
*** Call stack at first throw:
If a try/catch block does not work, how am I supposed to check for an exception here? Shouldn't it be working?
Thank you.
I don't think the try-catch code wasn't working. The log says "uncaught exception" so this error happens somewhere else in your code.

Objective C - Caught exception causes crash

I'm doing some Objective C tests. I'm raising a custom exception with this code:
- (double)foo:(int)x{
if (x == 0){
[NSException raise:#"InvalidX" format:#"X can't be 0"];
}
return 1/x;
}
and catching it with this code:
#try {
double y = [self foo:0];
} #catch (NSException *e) {
return;
}
It works good if i run the application in XCode but it crashes when i run the .app:
Exception Type: EXC_CRASH (SIGABRT)
Exception Codes: 0x0000000000000000, 0x0000000000000000
Application Specific Information:
objc[1769]: garbage collection is OFF
*** Terminating app due to uncaught exception 'InvalidX', reason: 'X can't be 0'
*** First throw call stack:
It doesn't look "uncaught"! I can't explain this

Fail to catch exception from proxy object under Xcode 3.2.3

I use HessianKit to communicate with server. In the situation of network or server down Hessian will throw exception, so I put every Hessian call in a #try ... #catch block. Everything worked fine until I upgraded Xcode from 3.2.2 to 3.2.3. I wrote the some testing code and found under Xcode 3.2.3, catch exception would be failed if the exception was thrown from a proxy object.
MyProxy.h:
#interface MyProxy : NSProxy {
}
#end
MyProxy.m:
#implementation MyProxy
- (id)init {
return self;
}
- (void)forwardInvocation:(NSInvocation *)invocation {
NSLog(#"Call method %#", NSStringFromSelector([invocation selector]));
[NSException raise:#"MyException" format:#"this is an exception"];
}
- (NSMethodSignature *)methodSignatureForSelector:(SEL)aSelector {
.....
}
#end
Code using MyProxy:
#try {
MyProxy *p = [[MyProxy alloc] init];
[p doSomething];
[p release];
}
#catch (NSException * e) {
NSLog(#"%#", e);
}
When these code build under xcode 3.2.2, the exception can be catched correctly. But under xcode 3.2.3, the program terminated after output following on the console:
2010-09-08 21:09:29.877 BriefCase[34651:40b] Call method doSomgthing
2010-09-08 21:09:29.879 BriefCase[34651:40b] *** Terminating app due to uncaught exception 'MyException', reason: 'this is an exception'
2010-09-08 21:09:29.880 BriefCase[34651:40b] Stack: (
45955152,
47113004,
45692683,
45692522,
151932,
45426420,
45423090,
9352,
4417860,
4421967,
4447550,
4429047,
4461016,
53399932,
45234332,
45230248,
4420129,
4453234,
8812,
8666
)
terminate called after throwing an instance of 'NSException'
Program received signal: “SIGABRT”.
What can I do?
I filed a bug with Apple, and the reply is:
It has been determined that this is a known issue, which is currently being investigated by engineering. This issue has been filed in our bug database under the original Bug ID# 7995323.
Maybe your project/target/executable settings have been messed up?
Is the "Enable Objective-C Exceptions" box ticked for your configuration/target/etc?
If it is, maybe you should file a bug with Apple here.

Try Catch Statement doesn't work on Simulator (but works on iPhone!!!)

I have an Exception catching statement in my code, like the following:
#try {
for(NSDictionary* s in users)
{
do something ....
}
}
#catch (NSException * exception) {
NSLog(#"APIRequesetBase readUserInfo: Caught %#: %#", [exception name], [exception reason]);
}
#finally {
}
So this try statement works perfectly on the iphone device, it can catch the exception.
However, on simulator, it can never catch the exception. It just crashes!!
I also try other simple try catch statement to test it,
and the simulator can never catch the exception. It just simply crashes!!
This issue is so strange.
Does anyone have this issue before?
Or is it because of the setting?
Thanks
This is a known bug that will be fixed in a future release.