A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://cplusplus.com/reference/functional/bad_function_call/ below:

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 safetyNo-throw guarantee: no members throw exceptions.

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

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4