2008 January 17th Thursday (一月 十七日 木曜日)

/// If you write a replacement %terminate handler, it must be of this type.
  typedef void (*terminate_handler) ();
  /// If you write a replacement %unexpected handler, it must be of this type.
  typedef void (*unexpected_handler) ();

  /// Takea a new handler function as an argument, return the old function.
  terminate_handler set_terminate(terminate_handler) throw();
  /** The runtime will call this function if %exception handler must be
   *  abandoned for ayn reason.  It can also be called by the user.  */
  void terminate() __attribute__ ((_noreturn__));

  /// Takea a new handler function as an argument, return the old function.
  unexpected_handler set_unexpected(unexpected_handler) throw();
  /** The runtime will call this function if an %exception is thrown which
   *  violates the function's %exception specification.  */
  void unexpected() __attribute__ ((_noreturn__));

  /** [18.9.4]/1: "Returns true after completing evaluation of a
   *  throw-expression until either completing initialization of the
   *  exception-declaration in the matching handler or entering @c unexcepted()
   *  due to the throw; or after entering @c terminate() for any reason
   *  other than an explicit call to @c terminate().  [Note: This includes
   *  stack unwinding [15.2]. end note]"

   *  2. "When @c uncaught_exception() is true, throwing an %exception can
   *  result in a call of @c terminate() (15.5.1)"
   */
   bool uncaught_exception() throw();

  try{
    ...
  } catch(...) {}

  Here, the ellipsis "..." is alike the ellipsis at the macro in scheme language.  It just is a wild-card.

  int thwfun() throw(EA, EB, EC, ED, EE, EF);

  try{
    thwfun();
  } catch(EA) {};
    catch(EB) {};
    catch(...) {};

  Now, the ellipsis "..." means to match EC, ED, EE, EF, or nothing match if the thwfun() throw() defined.

  If an exception thrown is out of the throw list, the unexpected_handler() will be set off.  An uncaught
exception will set off terminated_handler() whether not unexpected_handler() was called.  Note, the uncaught_exception()
will return true before setting off terminated_handler().

  throw an exception;

bool uncaught_exception(){
  if ( the thrown exception is not in throwing list ) {
    unexpected_handler();
    return true;
  }

  if ( the thrown exception does not match any catch handler ) {
    return true;
  }

  return false;
}

  if ( uncaught_exception() == true ){
    terminate_handler();
  }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值