WebSphere Message Service Clients: Web Services Client for C++, Version 1.1 作業系統: Linux, Windows

用戶端應用程式

Web 服務用戶端應用程式可以捕捉 Stub 可能擲出的不同錯誤類型, 並且適當地將內容解碼。

下列範例顯示用戶端應用程式如何捕捉和處理異常狀況。

// 試圖除以零。
try
{
	// 使用端點 URL 來建立 Web 服務。
	MathOps	ws( pszEndpoint);

	// 使用兩個參數來呼叫 div 方法。
	// 這樣會試圖將 1 除以 0。
	int		iResult = ws.div( 1, 0);

	// 輸出除法的結果。
	cout << "結果是 " << iResult << endl;
}
catch( DivByZeroStruct& dbzs)
{
	// 捕捉除以零 (divide by zero) 錯誤
	// 這是在 WSDL 中定義的使用者 SOAP 錯誤
	cout << "DivByZeroStruct 錯誤:\""
		<< dbzs.varString
		<< "\", " 
		<< dbzs.varInt
		<< ", " 
		<< dbzs.varFloat
		<< endl; 
}
catch( SpecialDetailStruct& sds)
{
	// 捕捉特殊詳細資料錯誤
	// 這是在 WSDL 中定義的使用者 SOAP 錯誤
	cout << "SpecialDetailStruct 錯誤: \""
		<< sds.varString
		<< "\"" 
		<< endl;
}
catch( OutOfBoundStruct& oobs)
{
	// 捕捉超出界限錯誤
	// 這是在 WSDL 中定義的使用者 SOAP 錯誤
	cout << "OutOfBoundStruct 錯誤: \""
		<< oobs.varString
		<< "\", " 
		<< oobs.varInt
		<< ", \"" 
		<< oobs.specialDetail->varString
		<< "\"" 
		<< endl;
}
catch( SoapFaultException& sfe)
{
	// 捕捉任何其他 SOAP 錯誤
	cout << "SoapFaultException: " << sfe.getFaultCode() << " " << sfe.what() << endl;
}
catch( AxisException& e)
{
		// 捕捉 AXIS 異常狀況
	cout << "AxisException: " << e.getExceptionCode() << " " << e.what() << endl;
}
	catch( exception& e)
{
		// 捕捉一般異常狀況
	cout << "不明的異常狀況:" << e.what() << endl;
}
	catch( ...)
{
		// 捕捉任何其他異常狀況
	cout << "未指定的異常狀況:" << endl;
}

Reference topic

使用條款 | 此頁的評等

「時間戳記」圖示前次更新: 28 Apr 2006
(C) Copyright IBM Corporation 2005. All Rights Reserved.
本資訊中心採用 Eclipse 技術。(http://www.eclipse.org)