(1)例外情報の設定
IDL言語でユーザ例外が定義されていた場合について、サーバアプリケーションプログラムの例を以下に示します。
IDLマッピング
【IDL言語】
module ODsample {
interface exptest{
exception testException { string reason; };
void op1() raises( testException );
};
};これをJava言語で記述すると、以下のようになります。
【Java言語】
<インタフェース>
package ODsample;
public interface exptestOperations{
public void op1()
throws ODsample.exptestPackage.testException;
}<ユーザ例外クラス>
package ODsample.exptestPackage;
public final class testException
extends org.omg.CORBA.UserException
{
public java.lang.String reason;
public testException(){}
public testException( java.lang.String _reason ){
reason = _reason;
}
}サーバアプリケーションでの処理
import org.omg.CORBA.*;
import org.omg.PortableServer.*;
import ODsample.*;
public class expServer {
public static void main( String args[] ) {
try {
// ORBの前処理
:
// POAオブジェクトの生成
:
// Servantの生成とそのPOAへの登録
:
// POAManagerの活性化
:
}
catch ( java.lang.Exception e ) {
//エラー処理
:
}
}
}
// Servantクラス
// サーバアプリケーションのメソッド
class expServant extends exptestPOA{
public void op1() throws ODsample.exptestPackage.testException {
throw new ODsample.exptestPackage.testException(
"Test of UserException" );
}
}(2)例外情報の獲得
サーバアプリケーションで例外を獲得する方法は、クライアントアプリケーションの例外処理と同様です。詳細については、“5.10 クライアントアプリケーションの例外処理”を参照してください。