views:

321

answers:

1

Which type exception checking required in linq inside try/catch block while performing CRUD(create,read,update,delete) OPERATIONS

for eg:

try {
    db.SubmitChanges(ConflictMode.ContinueOnConflict);
}
catch (ChangeConflictException e) {
    foreach (ObjectChangeConflict occ in db.ChangeConflicts) {
        // All database values overwrite current values.
        occ.Resolve(RefreshMode.OverwriteCurrentValues);
    }
}
+1  A: 

If it's not well-documented what exceptions will be thrown in normal use-case scenarios (and I can't say off the top of my head what will be thrown in your situation), I suggest trying to break it by performing operations you know will fail, and then add the exception that's thrown to the try/catch block.

If anything, trying to break your own code is a good debugging exercise, as it exposes problems that are likely to occur giving you a chance to recover gracefully.

Pwninstein
At the end of the day, these exceptions will extend from DbException (explicit or composed as the InnerException). I'd recommend catching this exception, but we might want to respond differently when the database is down versus a SQL Select statement failure.
David Andres