When scaffolding a new ApiController with asynchronous actions and Entity Framework support in Visual Studio 2013, some methods wrap DbContext.SaveChangesAsync calls in try-catch blocks.
For instance, the Put method,
try
{
await db.SaveChangesAsync();
}
catch (DbUpdateConcurrencyException)
{
if (!EmployeeExists(id))
{
return NotFound();
}
throw;
}
From msdn.microsoft.com about DbUpdateConcurrencyException,
Exception thrown by DbContext when it was expected that SaveChanges for an entity would result in a database update but in fact no rows in the database were affected.
The DbUpdateConcurrencyException is derived from DbUpdateException and there are a handful of other exceptions that can be thrown from the DbContext.SaveChangesAsync method.
I'm wondering why there are no catch clauses for these other exceptions? Is it for the sake of brevity? Or do they simply not belong at this level in the application?