C与C++中的异常处理17[19]

[入库:2005年8月18日] [更新:2007年3月24日]

本文简介:选择自 taodm 的 blog

1.4     version 4:匹配于c++标准运行库

    我们所有的standard_exception继承类都提供公有的成员

virtual char const *what() const;

来识别异常的动态类型。我不是随便选取的函数名:所有的c++标准运行库中的std::exception继承类为同样的目的提供了同样的公有成员。并且,what()是每个继承类的唯一的多态函数。

    你可能已经注意到:

#include <exception>

 

class structured_exception : public std::exception

   {

public:

   structured_exception(exception_pointers const &info) throw();

   static void install() throw();

   virtual char const *what() const throw();

   void const *where() const throw();

private:

   void const *address_;

   };

 

    因为structured_exception现在也是一个std:exception,我们可以用一个异常处理函数来同时捕获这个异常族:

catch (std::exception const &exception)

本文关键:异常
  相关方案
Google
 

本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)

go top