• Post Reply Bookmark Topic Watch Topic
  • New Topic

how to handle exception in web service method

 
cnivas redy
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi I'm writing a web service method. I want to know which is best way either throw an exception or sorround my statements with try - catch block.

I created a web service with Eclipse - axis2.
if i put try catch block in service method I'm able to generate my client using the WSDL and client is working fine. if i put methodname() throw exceptionname { } while generating client in eclipse by using the newly genarated WSDL with this change. it is(eclipse) giving an error message saying: client cann't be genarated SOAP FAULT is not found. but in my WSDL i can see the FAULT with my exception name.. wat could be the problem.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65519
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"cnu", please check your private messages for an important administrative matter.
 
Ivan Krizsan
Ranch Hand
Posts: 2198
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!
You are asking whether a method in an endpoint implementation class should throw an exception or not.
This depends whether you want to use the fault mechanism, which will be translated to an exception if you use a JAX-WS client, to tell the client that something went wrong when processing a request. Commonly, there are the following two options:
1. Catching an exception in the web service is a feasible approach if, for instance, there is an error that the web service can recover from.
For instance, the web service tries to access a resource that is temporarily unavailable. The exception is caught and the web service can retry accessing the resource.
2. Throwing an exception, that is, returning a fault as a result of an operation, may be better when there is an error that the web service is unable to recover from.
As an example: The web service is to store some data in a database, but a SQLException is thrown by the underlying database code.
Best wishes!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!