Alex Rivera | Logout

Is it Ok to throw exceptions back to a client from my service?

Asked 2010-02-05T16:44:27.037
10

I am writing a Java based service with WSDL for a .Net client to consume, and I thought that when I receive an invalid value from the client that I would throw an exception that my client could then catch and display in a message box or something to the user (the client is a desktop app).

I was wondering if it would be ok to use this approach or if there's a better way of doing it.

Edit
Report

2 Answers

8

.NET in general deals in FaultExceptions (wrapped SOAP faults) in WCF. I would assume that if you throw a proper SOAP Fault, that WCF would wrap this up into a FaultException by the time the client consumes the response, so they can have a try catch FaultException statement. This would still allow other non .NET clients to consume the service without breaking standards..

Just an idea anyway...

answered 2010-02-05T16:48:27.577
0

The first thing to tackle is preventing against exceptions being thrown by doing validation on data before it gets manipulated. IE

string func(string cat)
if(cat == null || cat.length == 0){
//set errorLabelText to "bad data"
return;
}
//else code

That being said only throw Exceptions in Exceptional cases.

answered 2010-02-05T16:48:12.207

Your Answer