Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9269667
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T15:10:54+00:00 2026-06-18T15:10:54+00:00

I am trying to add external data into SQLite / update existing data using

  • 0

I am trying to add external data into SQLite / update existing data using Core Data.

Basically, I am given a JSON from external web service and I am using following piece of code to find out whether I should add new or update existing object in DB.

NSFetchRequest *fetch = [[NSFetchRequest alloc] init];
[fetch setEntity:[NSEntityDescription entityForName:@"name" inManagedObjectContext:context]];
[fetch setPredicate:[NSPredicate predicateWithFormat:@"id = %@", [data valueForKey:@"key"]]];
NSArray *results = [context executeFetchRequest:fetch error:nil];

if (results.count == 1)
{
    // update existing
}
else
{
    // add new
}

The problem is: sometimes this code leads to an exception:

Thread 1: EXC_??? (11) (code=0, subcode=0x0)

The exception is raised in NSManagedObjectContext executeFetchRequest:error:

If I continue execution of my app everything seems ok.

Should I worry about this exception?

I mean it’s kind of annoying to have it but more important to know what is the cause and what are consequences of this exception?

Some additional detail (just in case it’s relevant):

  • Code above gets executed multiple times in a loop (about 250 thousand times).
  • Code runs on main thread (yeah, I know, but it’s kind of prototype).
  • Context was created on main thread.
  • External data is created in a background thread

[EDIT] Some more detail:

  • executeFetchRequest:error returns initialized array even when the exception was raised.
  • there is no error set when I provide error parameter to executeFetchRequest:error
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T15:10:56+00:00Added an answer on June 18, 2026 at 3:10 pm

    That’s not safe.

    You should check the return of the method to make sure you was handed an array back

    NSArray *results = [context executeFetchRequest:fetch error:nil];
    if (!results) {
        // An error occurred you should probably use the out error
    }
    

    Also CoreData seems to throw exceptions internally but handles them, so if you have an exception breakpoint set it will most likely get caught at random points from the CoreData stack – I’m saying this from past experience not sure if it’s documented anywhere but it is mentioned in this video Debugging Tips – Mike Hay

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to bring data into my app from an external file. everything's working
I'm trying to scrape data from an external JSON feed and store it in
When I'm trying to delete an external event from my calendar, if I add
Trying to add a class object into a List using reflection, but when invoking
I'm trying to get a simple GXT application to retrieve data from an external
I'd like to load some JSON data from an external service. However, it provides
I'm trying add data triggers to the default combobox style so each text item
I am trying to add the names of songs from an sd card on
I'm trying to sync data from a CRM server back to a separate service,
I'm using (fluent) nhibernate and I've run into a little problem. My data model

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.