前のページ次のページ上に戻るホーム BREW C++ ライブラリ & GUI フレームワーク & XML ミドルウェア : SophiaFramework UNIVERSE 5.0
static_exception
擬似例外処理機構を実現するテンプレート クラスです。
#include <SFCType.h.hpp>
class static_exception;
SFMTYPEDEFCLASS(static_exception)

解説

ARM コンパイラでは、C++ 言語の例外は使えません。

static_exception クラスは C++ 言語と類似の例外処理機構を提供します。

static_exception クラスを使う場合は、static_exception クラスから派生したクラスを作成する必要があります。

テンプレート引数 T には、SFCError 型を処理できるクラスを使用します。

参照

SophiaFramework でのエラー処理

メンバ

コンストラクタ/デストラクタ
static_exception( Void )
static_exception クラスのコンストラクタです。
~static_exception( Void )
static_exception クラスのデストラクタです。
パブリック関数
T const & static_catch( Void )
現在保持している例外を取得します。
プロテクト関数
Void static_throw( static_exception< T > const & param )
static_throw( T const & param )
例外を設定します。
Bool static_try( Void )
例外が保持されているかどうかを確かめます。

static_exception::static_exception
static_exception クラスのコンストラクタです。
[ public, explicit ]
static_exception(Void);

解説

例外の値を SFERR_NO_ERROR で初期化します。


static_exception::~static_exception
static_exception クラスのデストラクタです。
[ protected ]
~static_exception(
    Void    
);

static_exception::static_catch
現在保持している例外を取得します。
[ public, const ]
T const & static_catch(
    Void    
);

使用例

switch (static_catch()) {
  // エラーに応じた処理
  ...
}

static_exception::static_throw
例外を設定します。
[ protected ]
Void static_throw(
    static_exception< T > const & param   // コピー元の static_exception オブジェクト
);
[ protected ]
Void static_throw(
    T const & param   // 設定する例外
);

解説

C++ 言語の throw とは異なり、 static_throw 関数を呼び出しても実行中の関数を抜けることはありません。

関数を抜ける必要がある場合には、明示的に return を記述してください。

また、static_throw 関数を呼び出す関数には、 static_throws マクロを目印に付けることができます。

使用例

Void func(Void) static_throws
{
  // 現在の例外をチェック
  if (!static_try()) { 
    // エラーが発生している場合
    static_throw(SFERR_FAILED);
    return;
  }
  ...
}

static_exception::static_try
例外が保持されているかどうかを確かめます。
[ protected, const ]
Bool static_try(
    Void    
);

戻り値

  • 保持されていないとき : true
  • 保持されてるとき : false

使用例


// 例外が発生したかどうかのチェック
if (static_try()) { 
  // 例外が発生していない場合
  ...
} else {
  // 例外が発生している場合
  ...
}