Which type exception checking required in linq inside try/catch block while performing CRUD OPERATION
-
06-07-2019 - |
Question
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);
}
}
Solution
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.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow