Home > The Execution Monitor > Reference
PrevNext

The Execution Monitor reference

namespace boost {
  class execution_monitor;
  class execution_exception;
  class execution_aborted;
  class system_error;
}

Class execution_monitor

boost::execution_monitor — uniformly detects and reports the occurrence of several types of signals and exceptions, reducing various errors to a uniform execution_exception that is returned to a caller
boost::execution_monitor — 用多種類型的信號和異常進行統一的檢測和報告,將不同的錯誤用統一的 execution_exception 返回給調用者。

Synopsis

class execution_monitor {
public:
  // construct/copy/destruct
  execution_monitor();

  // execution
  int execute(unit_test::callback0<int> const&);

  // registration
  template<typename Exception, typename ExceptionTranslator> 
    void register_exception_translator(ExceptionTranslator const&, 
                                       boost::type<Exception>* = 0);
  unit_test::readwrite_property<bool> p_catch_system_errors;
  unit_test::readwrite_property<bool> p_auto_start_dbg;
  unit_test::readwrite_property<int> p_timeout;
  unit_test::readwrite_property<int> p_use_alt_stack;
  unit_test::readwrite_property<bool> p_detect_fp_exceptions;
};

Description

execution_monitor public construct/copy/destruct

  1. execution_monitor();

    Throws:

    Nothing.

    Effects:

    Constructs execution_monitor object.

execution_monitor execution

  1. int execute(unit_test::callback0<int> const& F);

    Parameters:

    F

    Returns:

    Value returned by monitored function F call. 調用被監控函數 F 返回的值。

    Throws:

    execution_exception on detected uncaught C++ exception, a hardware or software signal, trap, or other monitored function F premature failure.
    檢測到未捕獲的 C++ 異常,硬件或軟件信號,陷入或被監控函數 F 其它 premature failure (???) 時拋出 execution_exception

    Notes:

    method execute doesn't consider it an error for F to return a non-zero value
    F 返回非零值時 execute 方法並不認為是錯誤

execution_monitor registration

  1. template<typename Exception, typename ExceptionTranslator> 
      void register_exception_translator(ExceptionTranslator const& tr, 
                                         boost::type<Exception>* dummy = 0);

    Throws:

    Nothing.

    Effects:

    Registers translator function tr for an exception of type Exception. Translators get chained, so you can register as many as you want. The Exception type needs to be specified explicitly as the member function template argument. The translator function gets called when an exception of type Exception is thrown from within the monitored function. The translator receives a thrown exception object as its first argument. Result value of translator is ignored and no exception is reported if this function exits normally. But you can always rethrow the exception or throw a different one.
    為異常類型 Exception 註冊翻譯器函數 tr。翻譯器會被串連起來,所以你可以註冊任意多個。 Exception 類型作為成員函數模板參數必須被顯式指定。 當 Exception 類型的異常從被監控函數中拋出時翻譯器函數被調用。 翻譯器將拋出的異常對像作為第一個參數接收。 翻譯器的返回值被忽略,並且如果正常退出時也不會報告異常。 但你可以重新拋出這個異常或拋出另外一個。

Class execution_exception

boost::execution_exception — uniformly reports monitored function execution problems
boost::execution_exception — 被監控函數執行問題進行統一報告。

Synopsis

class execution_exception {
public:
  enum error_code;
};

Description

The class execution_exception is an exception used by the Execution Monitor to report problems detected during a monitored function execution. It intentionally does not allocate any memory so as to be safe for use when there is a lack of memory.
execution_exception 類用於 Execution Monitor 報告被監控函數執行中檢測到的問題。它被設計為不申請任何內存,所以在缺少內存的情況下同樣是安全的。

Type error_code

boost::execution_exception::error_code

Synopsis

enum error_code { no_error, user_error, cpp_exception_error, system_error, 
                  timeout_error, user_fatal_error, system_fatal_error };

Description

These values are sometimes used as program return codes. The particular values have been chosen to avoid conflicts with commonly used program return codes: values < 100 are often user assigned, values > 255 are sometimes used to report system errors. Gaps in values allow for orderly expansion.
這些值有時被當作程序的返回代碼。選擇特定的值來避免和程序通常使用的返回代碼衝突: 小於 100 的值通常是用戶指定的,大於 255 的值有時用來報告系統錯誤。值之間的間隔允許順序的擴展。

[Note] Note

Only uncaught C++ exceptions are treated as errors. If the application catches a C++ exception, it will never reach the execution_monitor.
只有未捕獲的 C++ 異常才被當作錯誤。如果應用捕獲了 C++ 異常,它就不會到達 execution_monitor

[Note] Note

The system errors include UNIX signals and Windows structured exceptions. They are often initiated by hardware traps.
系統錯誤包括 UNIX 信號和 Windows 結構化異常。它們通常由硬件陷入導致。

The implementation decides what a fatal_system_exception is and what is just a system_exception. Fatal errors are so likely to have corrupted machine state (like a stack overflow or addressing exception) that it is unreasonable to continue execution.
fatal_system_exception 和 system_exception 分別是什麼由實現決定。 致命錯誤一般會破壞機器狀態 (例如棧溢出或地址異常),所以沒有理由恢復執行。

Class execution_aborted

boost::execution_aborted — This is a trivial default constructible class. Use it to report graceful abortion of a monitored function execution.
boost::execution_aborted — 平凡的可默認構造的類。用來報告被監控函數適當地中止。

Synopsis

Class system_error

boost::system_error — This is a default constructible class. Use it to report failure in system call invocation.
boost::system_error — 平凡的可默認構造的類。用來報告在系統調用中的錯誤。

Synopsis

class system_error {
public:
  // construct/copy/destruct
  system_error();
  unit_test::readonly_property<long> p_errno;
};

Description

system_error public construct/copy/destruct

  1. system_error();

    Throws:

    Nothing.

    Effects:

    Constructs system_error object.

PrevUpHomeNext