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.
Related
My app always crashes and goes to the main.m file. It shows the following error in the output:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSURL initFileURLWithPath:isDirectory:]: nil string parameter'
libc++abi.dylib: terminating with uncaught exception of type NSException
How do I fix this?
This error implies that there is the function initFileURLWithPath:isDirectory: being called on a NSURL with a parameter being nil. Check your parameters that call this function and make sure they're not nil.
Hope that helps :)
This mean that [NSURL initFileURLWithPath:isDirectory:] nil so it crash.
You should put breakpoint and run again to find where is it crash. You can see image below:
After testing my app in a iOS 7 device, I got a crash calling containsString from NSString, and then I realised that that methods has NS_AVAILABLE(10_10, 8_0);
Is there anyway to check automatically my program to see if there is any other method that is not available in iOS 7?
How is possible to compile and app with deployment target of 7.0 and not saying any warning or error in these cases?
-[__NSCFString containsString:]: unrecognized selector sent to instance 0x1702297c0
2015-10-23 12:03:37.655 WA[1434:60b] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFString containsString:]: unrecognized selector sent to instance 0x1702297c0'
* First throw call stack:
(0x183bd2f50 0x1900dc1fc 0x183bd7c04 0x183bd5930 0x183af55dc 0x1002a2c08 0x1000c71dc 0x1000caa88 0x1000c69bc 0x1000f3a4c 0x186c1055c 0x186c0ff08 0x186c099ec 0x186b9d8cc 0x186b9cad0 0x186c09044 0x1897bb504 0x1897bb030 0x183b92e90 0x183b92df0 0x183b91014 0x183ad1c20 0x186c081c8 0x186c02fdc 0x1000b6040 0x1906cfaa0)
libc++abi.dylib: terminating with uncaught exception of type NSException
You should use rangeOfString instead of containsString. Since rangeOfString available from iOS 2.0, you will not get crash on this.
Code snippets,
NSString *string = #"https://www.google.co.in/";
NSString *substring = #"http";
if ([oneContent rangeOfString:subString].location == NSNotFound) {
NSLog(#"string does not contain substring");
} else {
NSLog(#"string contains substring!");
}
Otherwise you can add category class for NSString and have a method like containsString: where you can implement the above code. It'll work dynamically.
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.
Objective C gives me a run-time error for the indicated line of code
-(void) play: (int)i at: (int)j {
if ([self.board[i][j] isEqualToString:#""]){
if (xplays) {
self.board[i][j] = #"x"; //<-----HERE
}
else
self.board[i][j] = #"x";
}
xplays = !xplays;
}
board is a property. The error message is
[__NSArrayI replaceObjectAtIndex:withObject:]: unrecognized selector sent to instance 0x7123120
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayI replaceObjectAtIndex:withObject:]: unrecognized selector sent to instance 0x7123120'
Do I need to use C-arrays for this kind of assignment?
You should be using an NSMutableArray.
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.