WebSphere Web Services Client for C++, Version 1.0.1 Operating Systems: Linux, Solaris

Client application

A web service client application can catch the different types of fault that may be thrown by the stub and decode the contents appropriately.

The following example shows how a client application may catch and process exceptions.

// Attempt to divide by zero.
try
{
	// Create the Web Service with an endpoint URL.
	MathOps	ws( pszEndpoint);

	// Call the div method with two parameters.
	// This will attempt to divide 1 by 0.
	int		iResult = ws.div( 1, 0);

	// Output the result of the division.
	cout << "Result is " << iResult << endl;
}
catch( DivByZeroStruct& dbzs)
{
	// Catch a divide by zero fault
	// This is a user soap fault defined in the WSDL
	cout << "DivByZeroStruct Fault: \"" 
		<< dbzs.varString 
		<< "\", " 
		<< dbzs.varInt 
		<< ", " 
		<< dbzs.varFloat 
		<< endl; 
}
catch( SpecialDetailStruct& sds)
{
	// Catch a special detail fault
	// This is a user soap fault defined in the WSDL
	cout << "SpecialDetailStruct Fault: \"" 
		<< sds.varString 
		<< "\"" 
		<< endl;
}
catch( OutOfBoundStruct& oobs)
{
	// Catch an out of bounds fault
	// This is a user soap fault defined in the WSDL
	cout << "OutOfBoundStruct Fault: \"" 
		<< oobs.varString 
		<< "\", " 
		<< oobs.varInt 
		<< ", \"" 
		<< oobs.specialDetail->varString 
		<< "\"" 
		<< endl;
}
catch( SoapFaultException& sfe)
{
	// Catch any other SOAP faults
	cout << "SoapFaultException: " << sfe.getFaultCode() << " " << sfe.what() << endl;
}
catch( AxisException& e)
{
	// Catch an AXIS exception
cout << "AxisException: " << e.getExceptionCode() << " " << e.what() << endl;
}
catch( exception& e)
{
	// Catch a general exception
cout << "Unknown Exception: " << e.what() << endl;
}
catch( ...)
{
	// Catch any other exception
cout << "Unspecified Exception: " << endl;
}

Reference topic

Terms of Use | Rate this page

Timestamp iconLast updated: 12 Dec 2005
(C) Copyright IBM Corporation 2005. All Rights Reserved.
This information center is powered by Eclipse technology. (http://www.eclipse.org)