Error abfangen bei executeFetchRequest

  • Error abfangen bei executeFetchRequest

    Ich führe einen Fetchrequest wie gewohnt aus:
    // Context und Request werden deffiniert ...
    NSError *error = nil;
    NSArray *results = [context executeFetchRequest:request error:&error]; //HIER

    if (error == nil) {
    }
    Funktioniert auch wunderbar. Wenn ich aber z.B. beabsichtigt einen falschen Entity Name eintrage, stürtzt die App sofort bei executeFetchRequest (//HIER) ab. Obwohl ich ja eigentlich erst gucken möchte ist alles gut gelaufen, dann weitermachen, sonst ignorieren.
    Was mach ich falsch? Da sollte doch eigentlich ein error rausfallen ohne dass die App komplett crasht?

    Merci!

    Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von Baschdi ()

  • Das ist einfach. Ex wird eine Exception generiert.
    Key-value coding access pattern
    The access pattern key-value coding uses for managed objects is largely the same as that used for subclasses of NSObject—seevalueForKey:. The difference is that, if after checking the normal resolutions valueForKey: would throw an unbound key exception, the key-value coding mechanism for NSManagedObject checks whether the key is a modeled property. If the key matches an entity's property, the mechanism looks first for an accessor method of the form primitive[i]Key[/i], and if that is not found then looks for a value for [i]key[/i] in the managed object's internal storage. If these fail, NSManagedObject throws an unbound key exception (just like valueForKey:).