I started using Entity Framework 4.3.1 with code first approach.
I want to avoid application crash when database server is shut down or unavailable catching specific exceptions. Imagine this short sample piece of code:
using (var db = new MyContext())
{
var people = new People();
db.People.AddObject(people);
db.SaveChanges();
}
When server is shut down, I receive ProviderIncompatibleException. If I try to modify code catching ProviderIncompatibleException like this
using (var db = new MyContext())
{
try
{
var people = new People();
db.People.AddObject(people);
db.SaveChanges();
}
catch(ProviderIncopatibleException)
{
}
}
I receive compiler error "The type caught or thrown must be derived from System.Exception". How can I catch most specific Exception using Entity framework? Thank you for help.