Home C&C++函数库 c++ 语法 程序源码 Linux C库

std::

bad_function_call

类模板  <functional>

class bad_function_call;

错误调用时抛出异常
exceptionbad_function_call

空function对象在调用其函数调用时抛出的类型。

空函数对象是没有目标可调用对象(target callable object)的function对象。
该类派生自exception。有关标准异常的成员定义,请参阅exception类。

☣  示例



// bad_function_call example
#include <iostream>     // std::cout
#include <functional>   // std::function, std::plus, std::bad_function_call

int main () {
  std::function<int(int,int)> foo = std::plus<int>();
  std::function<int(int,int)> bar;

  try {
    std::cout << foo(10,20) << '\n';
    std::cout << bar(10,20) << '\n';
  }
  catch (std::bad_function_call& e)
  {
    std::cout << "ERROR: Bad function call\n";
  }

  return 0;
}

输出:
30
ERROR: Bad function call

☂ 异常安全性



无抛出保证:没有成员抛出异常。

🍄  另请参阅



exception 标准异常类(类)
function 函数包装器(类模板)

联系我们 免责声明 关于CandCplus 网站地图