Namespaces
Variants

std:: bad_function_call

From cppreference.net
Utilities library
Function objects
Function wrappers
(C++11)
(C++11)
bad_function_call
(C++11)
Function invocation
(C++17) (C++23)
Identity function object
(C++20)
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++20* )
( until C++20* )
( 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++20* )
( until C++20* )
Défini dans l'en-tête <functional>
class bad_function_call ;

std::bad_function_call est le type de l'exception levée par std::function::operator() si le wrapper de fonction n'a pas de cible.

cpp/error/exception std-bad function call-inheritance.svg

Diagramme d'héritage

Table des matières

Fonctions membres

(constructeur)
construit un nouvel objet bad_function_call
(fonction membre publique)
operator=
remplace l'objet bad_function_call
(fonction membre publique)
what
retourne la chaîne explicative
(fonction membre publique)

std::bad_function_call:: bad_function_call

bad_function_call ( ) noexcept ;
(1) (depuis C++11)
bad_function_call ( const bad_function_call & other ) noexcept ;
(2) (depuis C++11)

Construit un nouvel objet bad_function_call avec une chaîne d'octets terminée par un caractère nul définie par l'implémentation, accessible via what() .

1) Constructeur par défaut.
2) Constructeur de copie. Si * this et other ont tous deux le type dynamique std::bad_function_call , alors std:: strcmp ( what ( ) , other. what ( ) ) == 0 .

Paramètres

other - un autre objet d'exception à copier

std::bad_function_call:: operator=

bad_function_call & operator = ( const bad_function_call & other ) noexcept ;
(depuis C++11)

Assigne le contenu avec celui de other . Si * this et other ont tous deux le type dynamique std::bad_function_call alors std:: strcmp ( what ( ) , other. what ( ) ) == 0 après l'assignation.

Paramètres

other - autre objet d'exception à assigner

Valeur de retour

* this

std::bad_function_call:: what

virtual const char * what ( ) const noexcept ;
(depuis C++11)

Retourne la chaîne explicative.

Valeur de retour

Pointeur vers une chaîne terminée par un caractère nul, définie par l'implémentation, contenant des informations explicatives. La chaîne est adaptée à la conversion et à l'affichage en tant que std::wstring . Le pointeur est garanti d'être valide au moins jusqu'à ce que l'objet exception duquel il est obtenu soit détruit, ou jusqu'à ce qu'une fonction membre non constante (par exemple, l'opérateur d'affectation par copie) sur l'objet exception soit appelée.

Notes

Les implémentations sont autorisées mais non obligées de redéfinir what() .

Hérité de std:: exception

Fonctions membres

[virtuel]
détruit l'objet exception
(fonction membre publique virtuelle de std::exception )
[virtuel]
retourne une chaîne explicative
(fonction membre publique virtuelle de std::exception )

Exemple

#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';
    }
}

Sortie possible :

bad function call

Rapports de défauts

Les rapports de défauts modifiant le comportement suivants ont été appliqués rétroactivement aux normes C++ précédemment publiées.

DR Appliqué à Comportement tel que publié Comportement correct
LWG 2233 C++11 what() retournait toujours la même chaîne explicative
que std::exception::what()
retourne sa propre
chaîne explicative

Voir aussi

(C++11)
enveloppe copiable de tout objet appelable constructible par copie
(modèle de classe)