Question

I am seeing Exception handling in Apache Axis2 Webservices . My Skelton class throws a Userdefined Exception named as "NoUserFound" , which in have configured inside WSDL file

Inside my skelton class

public samples.quickstart.xsd.GetPriceResponse getPrice(
            samples.quickstart.xsd.GetPrice getPrice0)
            throws GetSolutionByIdFault {

        samples.quickstart.xsd.GetPriceResponse response = new samples.quickstart.xsd.GetPriceResponse();
                 response.set_return("Hi");
        String value = (String) getPrice0.getSymbol();
        if (value.equals("Pavan"))
            throw new GetSolutionByIdFault("name not present");
        return response;
}

Inside my client class , i am handling this in this way :

try {
  // Some Logic here 
    }
    catch (AxisFault er) {
    er.getMessage();
    }
    catch (Exception e) {
    e.printStackTrace();
    }

So when ever a user defined exception is thrown for example (GetSolutionByIdFault) , i am handling it in the AxisFault block .

is this the correct approach ??

Était-ce utile?

La solution

It depends on what you have to do in order to handle the exception. If you need to do special things according to the backend exception then you need to catch each and every exception and handle them separately.

Normally I used to handle exceptions separately.

Autres conseils

Yes, that looks fine - if you want, you catch more specific exceptions as well...

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top