目录

what

描述 (Description)

它用于获取字符串标识异常。

声明 (Declaration)

以下是std :: what的声明。

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

C++11

virtual const char* what() const noexcept;

参数 (Parameters)

没有

返回值 (Return Value)

它返回一个空终止的字符序列,可用于标识异常。

异常 (Exceptions)

No-throw guarantee - 没有成员抛出异常。

例子 (Example)

在下面的示例中为std :: what。

#include <iostream>       
#include <exception>      
struct ooops : std::exception {
   const char* what() const noexcept {return "Ooops! It is a identity error\n";}
};
int main () {
   try {
      throw ooops();
   } catch (std::exception& ex) {
      std::cout << ex.what();
   }
   return 0;
}

样本输出应该是这样的 -

Ooops! It is a identity error
↑回到顶部↑
WIKI教程 @2018