I have a MVC project that makes a call to a WCF service. The WCF service method, in the case of business rule failure, throws its own exception, CarTooOldException. This has a string that I want to show to the user, "Car is too old".
public class CarTooOldException : Exception
{
public CarTooOldException(string message) : base(message)
{ }
}
My MVC code will catch an exception but the type is a FaultException. The message inside is correct however ("Car is too old").
Without changing the WCF service, is there a way to detect that this is a CarTooOldException? A call to .GetType() doesn't tell me.
How can I be sure that if I see this FaultException that the message is a user-friendly one and safe to show the user?
Right now I fear my only choice is to look a the strings the WCF method throws and do a .Contains() on the message property.
Aucun commentaire:
Enregistrer un commentaire