Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>So here is what I did. We have a few custom exceptions in our application such as BusinessRuleException and ProcessException, WCF supports both FaultException and <code>FaultException&lt;T&gt;</code>.</p> <p>General practice seems to be that you always throw FaultException to the client in the case of a general error or an error that you dont want to display exactly what happened. In other cases you can pass <code>FaultException&lt;T&gt;</code> where T is a class with information about the particular exception.</p> <p>I created this concept of Violations in the application, which basically meant that any custom exception had a property containing the corresponding Violation instance. This instance was then passed down to the client enabling the client to recognize when a recoverable error had occured.</p> <p>This solved part of the problem, but I still wanted a general catch all that would allow me to centeralize logging. I found this by using the IErrorHandle interface and adding my own custom error handler to WCF. Here is the code:</p> <pre><code>public class ServiceHostGeneralErrorHandler : IErrorHandler { public void ProvideFault(Exception ex, MessageVersion version, ref Message fault) { if (ex is FaultException) return; // a general message to the client var faultException = new FaultException("A General Error Occured"); MessageFault messageFault = faultException.CreateMessageFault(); fault = Message.CreateMessage(version, messageFault, null); } public bool HandleError(Exception ex) { // log the exception // mark as handled return true; } } </code></pre> <p>Using this method, I can convert the exception from whatever it is to something that can be easily displayed on the client while at the same time logging the real exception for the IT staff to see. So far this approach is working quite well and follows the same structure as other modules in the application.</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