Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Entity framework - how to detect recoverable vs unrecoverable exceptions

In my current project, we're using Entity Framework, and in this context to store data coming in from a remote system. When I attempt to save objects, I need to reliably tell if an exception is something that can be recovered from or not.

To clarify, by "recovered from" I mean that simply attempting the operation again a bit later would be safe and would potentially succeed. This would include issues with network connectivity, the DB server being restarted or similar situations.

Unrecoverable in this context would be basically anything else, including integrity constraints and internal Entity Framework errors (the database being out of sync with the EF model). It could be argued that some integrity constraints might be recovered from if someone "fixes" the data, but in this case there will be only a single writer.

Is there a reliable way of categorizing an exception coming from Entity Framework into one of these two categories?

like image 441
SoftMemes Avatar asked Nov 05 '22 09:11

SoftMemes


1 Answers

I think you'll have to come up with your own list of exceptions that you are willing to test for and handle. The list of exceptions that you could classify as recoverable or not wouldn't likely be the same in any two environments. That said, perhaps you can start here:

Where to find ADO.NET Entity Framework error list?

like image 118
Tim Lehner Avatar answered Nov 09 '22 06:11

Tim Lehner