質問

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 ??

役に立ちましたか?

解決

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.

他のヒント

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

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top