Note that there are some explanatory texts on larger screens.

plurals
  1. POhow do I catch a NSRangeException?
    primarykey
    data
    text
    <p>I want my app to continue gracefully when the online server messes up. I tried to wrap the dangerous line in a <code>@try</code> block. Yet it is still crashing like so:</p> <p>the method:</p> <pre><code>+ (NSArray *)findAllFor:(NSObject *)ratable { NSString *ratingsPath = [NSString stringWithFormat:@"%@%@/%@/%@%@", [self getRemoteSite], [ratable getRemoteCollectionName], [ratable getRemoteId], [self getRemoteCollectionName], [self getRemoteProtocolExtension]]; Response *res = [ORConnection get:ratingsPath withUser:[[self class] getRemoteUser] andPassword:[[self class] getRemotePassword]]; NSArray *ratings; @try { ratings = [self fromXMLData:res.body]; } @catch (NSException *e) { ratings = [NSArray array]; } return ratings; } </code></pre> <p>the stack trace:</p> <pre> Program received signal: “SIGABRT”. 2010-08-07 16:38:51.846 TalkToHer[68608:7003] *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[NSArray objectAtIndex:]: index 1 beyond bounds [0 .. 0]' *** Call stack at first throw: ( 0 CoreFoundation 0x02932919 __exceptionPreprocess + 185 1 libobjc.A.dylib 0x02a805de objc_exception_throw + 47 2 CoreFoundation 0x0292858c -[__NSArrayI objectAtIndex:] + 236 3 TalkToHer 0x00009fa7 -[FromXMLElementDelegate parser:didEndElement:namespaceURI:qualifiedName:] + 425 4 Foundation 0x0017bcc1 _endElementNs + 453 5 libxml2.2.dylib 0x02d9deb6 xmlParseXMLDecl + 1353 6 libxml2.2.dylib 0x02da8bc1 xmlParseChunk + 3985 7 Foundation 0x0017b4c2 -[NSXMLParser parse] + 321 8 TalkToHer 0x0000b14d +[NSObject(XMLSerializableSupport) fromXMLData:] + 201 9 TalkToHer 0x00031a6c +[Rating findAllFor:] + 320 10 TalkToHer 0x00032d67 -[FirstClassContentPiece(Ratable) updateRatings] + 96 11 TalkToHer 0x00004d5f __-[InspirationController tableView:didSelectRowAtIndexPath:]_block_invoke_3 + 33 12 libSystem.B.dylib 0x9792efe4 _dispatch_call_block_and_release + 16 13 libSystem.B.dylib 0x97921a4c _dispatch_queue_drain + 249 14 libSystem.B.dylib 0x979214a8 _dispatch_queue_invoke + 50 15 libSystem.B.dylib 0x979212be _dispatch_worker_thread2 + 240 16 libSystem.B.dylib 0x97920d41 _pthread_wqthread + 390 17 libSystem.B.dylib 0x97920b86 start_wqthread + 30 ) terminate called after throwing an instance of 'NSException' </pre> <p>Is my syntax for <code>@try @catch</code> wrong? I attempted to add a <code>@catch</code> block for <code>NSRangeException</code> but it seems that's not the right approach (it's not a class).</p> <p>Also, the server error is caused by <code>[ratable getRemoteId]</code> sometimes returning <code>(null)</code> instead of an integer. This behavior seems pretty unpredictable; if anyone has a clue why <code>ObjectiveResource</code> might be doing that it would be helpful. But I still would like to know how to use <code>@try @catch</code>.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload