bad_function_call Class

Reports a bad function call.

class bad_function_call
    : public std::exception {
    };

The class describes an exception thrown to indicate that a call to operator() on a function Class object failed because the object was empty.

 

// std_tr1__functional__bad_function_call.cpp 
// compile with: /EHsc 
#include <functional> 
#include <iostream> 
 
typedef double (Fd)(double); 
typedef std::function<Fd> Myfunc; 
 
double square(double x) 
    { 
    return (x * x); 
    } 
 
int main() 
    { 
    Myfunc fd0(square); 
    std::cout << "x * x == " << fd0(3) << std::endl; 
 
    try 
        { 
        Myfunc fd1; 
        std::cout << fd1(3) << std::endl; 
        } 
    catch (const std::bad_function_call&) 
        { 
        std::cout << "bad function call" << std::endl; 
        } 
    catch (...) 
        { 
        std::cout << "unknown exception" << std::endl; 
        } 
 
    return (0); 
    } 
 
x * x == 9
bad function call

Header: <functional>

Namespace: std

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft