std::bad_function_call

Header: <functional>

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

# Declarations

class bad_function_call;

# Parameters

# Return value

*this

# Notes

Implementations are allowed but not required to override what().

# Example

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

# Defect reports

DRApplied toBehavior as publishedCorrect behavior
LWG 2233C++11what() always returned the same explanatorystring as std::exception::what()returns its ownexplanatory string

# See also