Interstage Application Server アプリケーション作成ガイド (CORBAサービス編)
目次 索引 前ページ次ページ

第6章 アプリケーションの開発(Java言語)

6.13 サーバアプリケーションの例外処理

(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)例外情報の獲得

 サーバアプリケーションで例外を獲得する方法は、クライアントアプリケーションの例外処理と同様です。詳細については、“クライアントアプリケーションの例外処理”を参照してください。


目次 索引 前ページ次ページ

All Rights Reserved, Copyright(C) 富士通株式会社 2005