Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to properly define exception strategy in .NET enterprise application with DDD pattern?
    text
    copied!<p>I am developing enterprise-like project by using DDD pattern. I have following projects in my C# solution:</p> <ul> <li><p>Domain model - DLL project</p></li> <li><p>WebUI - ASP.NET MVC3 project</p></li> <li><p>DesktopUI - WPF project</p></li> <li><p>DAL - Entity Framework Code First </p></li> <li><p>Persistance - SQL Server Database</p></li> </ul> <p>This project is not large but I am trying to use all good practices of enterprise applications. </p> <p>What I'd like to define now is exception strategy but I am not sure how to approach that. I should probably use Enterprise Library Exception Handling and Logging Blocks but I am not sure how to fit that into the picture. Some concrete scenarios I am trying to resolve in my head are following:</p> <ul> <li><p>If new Entity is created by the user in the WPF application, and Save button is clicked how should error be reported and logged in case an exception occurs at different levels (eg. entity is not properly created according to domain rules, or there was an error trying to persist new object to database)</p></li> <li><p>User tries to retrieve unknown entity from database (eg. from WebUI by specifying unknown entity Id in URL)</p></li> </ul> <p>I understand I can define custom exceptions but I am not quite sure where and how. Should they be defined per each layer? I know there is wrapping exception practice but again not quite sure how to best use that pattern.</p> <p>Also should I create one custom exception for each error in some layer (eg. UserAlreadyExistInDatabaseException for trying to save two users with same email, and UnknownUserDatabaseException if trying to get unknown user from DB) or should I have one exception type that handles multiple layer errors (eg. DatabaseException, and then differentiate errors with custom property or Exception.Message property).</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload