• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Design of Exception handling on Web Services

 
Ranch Hand
Posts: 2108
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This topic is brought by my thoughts on how to design a good exception/error system in a web service client and server system. The issues are below:

1. Should we return a String or a business class, etc. instead of a 'throw'n exception on web service interfaces? Should we leave the exception throwing, for web service layer (nothing to do with business layer), e.g. failure to connect to server?

e.g.
Result performService(Request)
where Result can represent an exception standard, in addition to being the no-error result

instead of

Result performService(Request) throws MyServiceException

2. java.lang.Exception's parent Throwable, has the field non-transient java.lang.StackTraceElement. java.lang.StackTraceElement doesnt have an empty constructor. It is causing a failure when trying to pass a java.lang.Exception from server to client, as a 'thrown' object (i.e. declared in 'throws' clause).

==========================================================

(These came when I was using Xfire to serve the service, and axis to generate the client. I am not sure if this is the same with other implementations.)
 
Jesus Angeles
Ranch Hand
Posts: 2108
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My current workaround is:

Extend java.lang.Exception, adding a field 'String causeClass'. causeClass will contain the full class name of the Throwable inside the java.lang.Exception.cause field. (My business exception is in that java.lang.Exception.cause field.)

The client evaluates the string causeClass inside the thrown exception class.
 
It is no measure of health to be well adjusted to a profoundly sick society. -Krishnamurti Tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic