<functional>

std::bad_function_call

class bad_function_call;
呼叫函式時丟擲異常

呼叫空的 function 物件時丟擲的型別。

空的函式物件 是沒有目標可呼叫物件function 物件。

此類派生自 exception。有關標準異常的成員定義,請參閱 exception 類。

示例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
// 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


異常安全

無異常保證:無成員丟擲異常。

另見