473,388 Members | 1,340 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

Architecture question: Exceptions vs status codes

We're having an internal debate about the merits & demerits of
returning status codes in the output message vs exceptions to signify
errors in handling a Web method.
The status code camp is arguing that business rules related errors are
to be conveyed using status code while reserving the exception approach

(using SoapException) to system related errors (like say database
connection issues). This implies that GetFoo() returns a composite
message that includes StatusCode, Foo (the result) as well as other
error code/descriptions.
The cons of the status code approach is that it makes client side code
really painful:
try {
response = proxy.GetFoo();
switch ( response.StatusCode )
{
case Success:
// response.Foo is valid
case NotFound: // handle this error
case OtherError:
// look at response.ErrDetail for additional
context about the error
....
}
}
catch (SoapException ex)
{
// unpack the Detail element to figure out what happened &
handle it
// appropriately
}
The other big drawback, is that the client could completely ignore the
status code. Also, the status codes will have to be conveyed
"out-of-band" thru other means of documentation - the .wsdl alone is
perhaps not sufficient.
The exception camp is arguing for using Soap Faults in the WSDL &
throwing SoapExceptions from the web method. This allows for
consistent handling of all errors (business or system related errors)
on the client side.
The cons of the exception approach is that 1.1 WSDL simply ignores the
SOAP Fault when generating client side proxy code. [Other toolkits,
notably, Axis for e.g. turns the SOAP Faults into custom exceptions
which makes it easier for clients to handle them appropriately].
Does WSDL 2.0 and/or WCF (Indigo) handle SOAP Faults any better?
Although the exception approach seems like a hands down winner, are
there any scenarios where returning status code might make sense?? or
is exception approach the way to go always? Comments?
TIA

Dec 20 '05 #1
1 2665
I would never use status codes if exceptions are possible - and I say that
cause I'm working with a system that's not capable of generating SOAP fault
messages that can be interpreted by the client in a meaningful way and so I
have to use status codes there!.

If status codes are valueable for your solution, you still have the option
to include them in the SoapException and parse it at the client to throw new
exceptions that can be handled smoothly. It may not be elegant, but the code
will be much more readable and whenever you forget to catch an exception you
will note it (assuming there's not final catch {} clause).

While I'm convinced that exceptions are the better solution, I'm sure to see
other posts that will tell the opposite, because both approaches are valid.

Michael
"chen" <ve******@sig.com> schrieb im Newsbeitrag
news:11*********************@g47g2000cwa.googlegro ups.com...
We're having an internal debate about the merits & demerits of
returning status codes in the output message vs exceptions to signify
errors in handling a Web method.
The status code camp is arguing that business rules related errors are
to be conveyed using status code while reserving the exception approach

(using SoapException) to system related errors (like say database
connection issues). This implies that GetFoo() returns a composite
message that includes StatusCode, Foo (the result) as well as other
error code/descriptions.
The cons of the status code approach is that it makes client side code
really painful:
try {
response = proxy.GetFoo();
switch ( response.StatusCode )
{
case Success:
// response.Foo is valid
case NotFound: // handle this error
case OtherError:
// look at response.ErrDetail for additional
context about the error
....
}
}
catch (SoapException ex)
{
// unpack the Detail element to figure out what happened &
handle it
// appropriately
}
The other big drawback, is that the client could completely ignore the
status code. Also, the status codes will have to be conveyed
"out-of-band" thru other means of documentation - the .wsdl alone is
perhaps not sufficient.
The exception camp is arguing for using Soap Faults in the WSDL &
throwing SoapExceptions from the web method. This allows for
consistent handling of all errors (business or system related errors)
on the client side.
The cons of the exception approach is that 1.1 WSDL simply ignores the
SOAP Fault when generating client side proxy code. [Other toolkits,
notably, Axis for e.g. turns the SOAP Faults into custom exceptions
which makes it easier for clients to handle them appropriately].
Does WSDL 2.0 and/or WCF (Indigo) handle SOAP Faults any better?
Although the exception approach seems like a hands down winner, are
there any scenarios where returning status code might make sense?? or
is exception approach the way to go always? Comments?
TIA

Dec 21 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Gianni Mariani | last post by:
I'm involved in a new project and a new member on the team has voiced a strong opinion that we should utilize exceptions. The other members on the team indicate that they have either been burned...
8
by: Shane Groff | last post by:
I know this is a recurring discussion (I've spent the last 3 days reading through threads on the topic), but I feel compelled to start it up again. After reading through the existing threads, I...
10
by: Jakob Bieling | last post by:
Hi, somehow the prejudice of exceptions being rather slow (compared to, ie. returning an error value and checking that) keeps sticking around .. at least around me. I guess this is also why I...
2
by: Paul Reddin | last post by:
Hi, I've implemented calling a SP form a trigger using the CALL_PROCEDURE() UDF from http://www-106.ibm.com/developerworks/db2/library/techarticle/dm-0402greenstein/ A couple of questions...
1
by: benmorganpowell | last post by:
I have a small windows service which connects to a POP3 server at defined intervals, scans the available messages, extracts the required information and inserts the data into a SQL database. I am...
5
by: tryptik | last post by:
All- I have heard differing points of view on whether or not constructors should throw. I am working on a library, and I need to know if it is bad form for a consturctor to throw. Thanks -J
29
by: mailforpr | last post by:
Sometimes, I can't think of any good reason why I should have the program's logic thrown an exception. Except for catching the exception and printing "Uh, oh" to the screen. I also think that in...
13
by: mike3 | last post by:
Hi. (crossposted because the program is in C++ and some C++-related elements are discussed, hence comp.lang.c++, plus general program design questions are asked, hence comp.programming.) I'm...
37
by: Sweetiecakes | last post by:
Hello I'm a bit confused on how one should handle exceptions. I'm currently building an ADO.NET Windows Forms application. I've built a class for manipulating data within the database in...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.