class

<functional>

std::bad_function_call

Exception thrown on bad call


Type thrown by empty function objects when their functional call is invoked.

Empty function objects are function objects with no target callable object.

This class is derived from exception. See the exception class for the member definitions of standard exceptions.


Example

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;
}

Output:

30
ERROR: Bad function call


Exception safety

No-throw guarantee: no members throw exceptions.

See also

exception
Standard exception class (class)
function
Function wrapper (class template)