Okay so I've been working on a database class and was told to use exception. However I read on the Apple developer guide to avoid exceptions as much as possible and use NSError instead. (https://developer.apple.com/library/ios/#DOCUMENTATION/Cocoa/Conceptual/ObjectiveC/Chapters/ocExceptionHandling.html)
So it got me thinking: Am I using the right approach? Should I be using NSErrors in this case?
+(long)insertTrack:(Track *)track Database:(Database *)db {
@try {
sqlite3_exec(db.dataBase, "BEGIN", 0, 0, 0); //Start transaction
const char *sqlTrack = "INSERT INTO ...";
if(sqlite3_prepare_v2(db.dataBase, sqlTrack, -1, &addTrackStatement, NULL) != SQLITE_OK) {
@throw [NSException exeption....]
}
//Bind variables
sqlite3_bind_text(...);
if(SQLITE_DONE != sqlite3_step(addTrackStatement)) {
@throw [NSException exeption....]
}
else {
long insertedTrack = sqlite3_last_insert_rowid(db.dataBase);
sqlite3_exec(db.dataBase, "COMMIT", 0, 0, 0); //End transaction
return insertedTrack;
}
}
@catch(NSException *exception) {
//Log the exception and ROLLBACK!
}
@finally {
sqlite3_clear_bindings(addTrackStatement);
sqlite3_reset(addTrackStatement);
sqlite3_finalize(addTrackStatement);
}
}
So again my question: Should I use a return value to indicate that something had gone wrong with either the preparing or executing of the sql statement? Should I use NSError or use Exception like I am right now?