|
BDE 4.39.x Production Release
|
Provide an exception class thrown by bsl::function.
Provide an exception class thrown by bsl::function.
bsl::functionbsl_functional.h
This component provides a bsl::bad_function_call exception class when exceptions are enabled, and nothing otherwise. This exception is thrown by bsl::function::operator() when the function wrapper object has no target. If compiling as C++11 or later, bsl::bad_function_call is an alias for std::bad_function_call.
This section illustrates intended use of this component.
Suppose we want to write a null functor, the functional equivalent of a null pointer, which throws an exception when invoked. We can use the bsl::bad_function_call exception type as our common vocabulary for reporting the invocation of functors when they are not in a callable state.
First, we define the class and give it a call operator that unconditionally throws:
Then, we invoke the call operator inside a try block and confirm that the expected exception type is caught: