0

I'm using the CXF for developing webservices.

But I was wondering what is Best Practice for handling exceptions? Let's say I have a webservice-operation, create(User user). The incoming user is an instance of my User domain class, and can be saved directly by the UI Team by calling user.save()

If the save() for some reason fail (e.g. some Network connectivity fail , or some data validation error from User DTO ), how would Best Practice dictate that I serve this exception to the client?

I mean: Which type of Exception would be suitable?

Should this Exception be included in the operations signature ??

public Response createUser(User user);

@WebService
public interface EmpService {
public Response createUser(User user);
}

And how should the client-side handle this exception?

1
  • Are you asking whether the exception details will be in the response ? or threw a separate exception like this public Response createUser(User user) throws MyOwnUserException; Commented Nov 21, 2011 at 14:11

1 Answer 1

0

One company I was working in, with web services had almost 15 years of experience, so I have learned some things. We handled the exception simply by specified throws statement in the method. And if some expected error occurred, we just simply constructed the exception and throw it with the message which pointing to reason why something has failed.

The client should handle all exceptions thrown by service in anyway he likes to do it. If you are developing a web service, you need to be worried about how to correctly create an exception with appropriate reason in it. And when exception occurs the client will see it anyway.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.