Catching Sql Exception In Entity Framework4?What is the best practice?

What practices do you use in your datalayer to catch sql exceptions? Has anybody written a Generic Sql Exception handler where they catch the most common errors ?

how do you do it any examples out there?



Handle unexpected exception by the underlying layer only

Exceptions from your data layer (in this case Entity Framework) should be handled only by your business layer. The business layer can raise then (if necessary) a more high-level exception for your presentation layer (UI).

Don't throw and catch exceptions across more than one layer of your application. This is considered to be bad practice. The presentation layer should only handle business layer exceptions.

Never swallow exceptions by using:

try {} catch (Exception) { // who cares }

Catch expected exceptions as early as possible

Always try to handle expected exceptions (e.g. FileNotFoundException) as soon as possible. If you can handle it, handle it directly there. If not, re-throw a Custom Exception and handle it in your underlying layer.

Don't clear the stack trace when re-throwing an exception

Catch and re-throw implicitly (see)

try {} catch (Exception) { throw; }

and not explicitly

try {} catch (Exception ex) { throw ex; }

Need Your Help

Google MAPs API for android limit 2500 requests/day is per client device or per application key?

android google-maps limit google-maps-android-api-2 license-key

Sorry, I found similar questions - but not the answers: only discussions. I'm developing android application which is intended to place points and draw routes on map. In case Google limits using of...

Read values from the Office 2007 ribbon using VBA

vba word-vba ribbon office-2007

Using VBA, can I find out the value of a text (combobox) control on the Word 2007 ribbon?