std::bad_function_call

From cppreference.com
< cpp‎ | utility‎ | functional
 
 
Utilities library
Type support (basic types, RTTI, type traits)
Dynamic memory management
Error handling
Program utilities
Variadic functions
Date and time
Function objects
(C++11)
Relational operators
Optional and any
(C++17)
(C++17)
Pairs and tuples
(C++11)
(C++17)
Swap, forward and move
(C++14)
(C++11)
(C++11)
Type operations
(C++11)
(C++17)
 
Function objects
Function wrappers
(C++11)
(C++11)
bad_function_call
(C++11)
(C++17)
Bind
(C++11)
(C++11)
(C++11)
Reference wrappers
(C++11)(C++11)
Operator wrappers
Negators
(deprecated)
(deprecated)
(deprecated)
(deprecated)
Searchers
Old binders and adaptors
(until C++17)
(until C++17)
(until C++17)
(until C++17)
(until C++17)(until C++17)(until C++17)(until C++17)
(until C++17)
(until C++17)(until C++17)(until C++17)(until C++17)
(until C++17)(until C++17)
(until C++17)(until C++17)
 
Defined in header <functional>
class bad_function_call;
(since C++11)

std::bad_function_call is the type of the exception thrown by std::function::operator() if the function wrapper has no target.

cpp/error/exceptionstd-bad function call-inheritance.svg
About this image

Inheritance diagram

Contents

[edit] Member functions

(constructor)
bad_function_call()
(public member function)

std::bad_function_call::bad_function_call()

bad_function_call();

Constructs a new instance of std::bad_function_call.

Parameters

(none)

Exceptions

noexcept specification:  
noexcept
  

Inherited from std::exception

Member functions

[virtual]
destructs the exception object
(virtual public member function of std::exception)
[virtual]
returns an explanatory string
(virtual public member function of std::exception)

[edit] Example

#include <iostream>
#include <functional>
 
int main()
{
    std::function<int()> f = nullptr;
    try {
        f();
    } catch(const std::bad_function_call& e) {
        std::cout << e.what() << '\n';
    }
}

Output:

bad function call

[edit] See also

(C++11)
wraps callable object of any type with specified function call signature
(class template)