4

I have run into a disturbing/baffling bug. Core Data seemed to be swallowing its own exception! When using the (super-useful) CoreDataHelper, I had written a badly formed fetch that resulted in a "Unimplemented SQL generation for predicate" exception. That part's simple, what's really weird is that this exception was being caught somewhere and swallowed, meaning that my code just skipped the rest of the method after that fetch and returned to the main loop without any console messages. Quite infuriating.

Eventually I was able to wrap the actual fetch request in a @try statement and @catch the exception:

@try{
fetchResults = [managedObjectContext executeFetchRequest:request error:&error];
    NSLog(@"fetch successful");
}
@catch (NSException* exception) {
    NSLog(@"caught exception!\n\n%@\n\n%@\n\n%@",[exception name], [exception reason], [exception userInfo]);
}

This let me figure out what it was, but it still makes no sense that it would be getting caught somewhere. I have not used @try/@catch anywhere else in my code other than to test this.

I also tried creating a blank Core Data project and using CoreDataHelper without the @try/@catch statement to try and isolate the problem, with nothing else in the project, CoreDataHelper works as it should, returning:

CoreDataTest[1044:11603] *** Terminating app due to uncaught exception   'NSInvalidArgumentException', reason: 'Unimplemented SQL generation for predicate ("test" LIKE attribute)'

So something in my project is catching and ignoring this exception, but it's not me unless I can somehow do that without using @catch.

What could it be?!

Rembrandt Q. Einstein
  • 1,101
  • 10
  • 23
  • Can you post the full code? I believe you have a predicate in here, and this is something that is leading to a problem. Just an outside thought, using a 'like' in predicate against a variable which is not a part of core data. – Reno Jones Feb 11 '13 at 17:44
  • Oh, I know that the issue was with the formatting of my predicate, my real question is "why is this exception getting caught and ignored unless I explicitly catch it myself?" – Rembrandt Q. Einstein Feb 11 '13 at 17:47
  • 1
    Do you by any chance get a "NSRunLoop ignoring exception ..." message in console when the exception happens and gets swallowed? I cannot find any actual Apple-provided documentation on `NSRunLoop` behavior regarding exceptions, but the accepted answer on the http://stackoverflow.com/questions/4648952/objective-c-exceptions question states that this situation is pretty common in some cases. – Egor Chiglintsev Feb 11 '13 at 18:18
  • Nope, no message in the console unless I @catch the exception myself. Maybe I'm missing a setting? – Rembrandt Q. Einstein Feb 11 '13 at 18:27
  • 1
    Is this happening in a GCD block or background thread? Does the exception get swallowed on the main thread? – ChrisH Feb 11 '13 at 18:35
  • This is happening in the main thread. – Rembrandt Q. Einstein Feb 11 '13 at 18:36

1 Answers1

2

Got it!

I'm using an external accessory (Linea Pro-4 barcode scanner/MSR) that has its own library, and that is what is catching the exception, even in their newest version of the framework.

I set up my blank test project to connect to the accessory before running the same fetch request, and bam! Swallows the exception!

Rembrandt Q. Einstein
  • 1,101
  • 10
  • 23