This week's book giveaway is in the Mac OS forum. We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line! See this thread for details.
We have a scenario where in we have to invoke a web service. This web service on exception situation may return multiple status codes. We want to raise a custom exception & populate this custom exception with with all the status codes & status messages returned by the web service.
From this service layer we have to send this exception object back to the Struts (controller layer). At the controller layer we populate the ActionMEssages(1 each for a status code) object which finally gets displayed on a error.jsp file.
What would be the best way to handle this multiple status codes scenario. Do post your thoughts
You could create a custom "complex" exception that encapsulates many more basic exceptions. As your service method works it can build a list of basic exceptions and add them all to the one big exception.
Or you can build a single Exception carryng a Collection (a List???) of simple Containers. Your Container is a class made up of only two attributes: ErrorCode e Message where the first one is a custom Enum value (if you are using a Java version graeter-equal to 1.5) and the Message is String (probably a code you can use as a key on a localization property file).
Probably the Paul Sturrock suggestion is more far-seeing and flexible. Maybe mine is easier to handle if all you have to do is to visualize some error messages on the Jsp or to put it in a switch statement. I recall you switch can work well with Enums. Doing the same with different types of Exceptions instances would force you to use a bunch of "instance of" inside a multi-branch if-else construct or to loop through the Exception Collection and to intentionally throw them so that a propr catch block can handle them in an adequate way.
SCJP 5 & 6, SCWCD 5, SCBCD 5
Joined: Oct 23, 2003
Will the complex exception class as you mentioned have a Collection object for storing basic exceptions. Can you ellaborate a bit on the structure of this complex exception class