◐ Shell
clean mode source ↗

std::bad_alloc — cppreference.com

De cppreference.com

<metanoindex/>

<tbody> </tbody>

Déclaré dans l'en-tête

<new>

class bad_alloc;

std::bad_alloc is the type of the object thrown as exceptions by the

to report failure to allocate storage.

cpp/error/exception

Inheritance diagram

Fonctions membres

constructs the bad_alloc object
(fonction membre publique)
replaces a bad_alloc object
(fonction membre publique)

renvoie une chaîne explicative

Original:

returns explanatory string

The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.


(fonction membre publique)

Inherited from std::exception

Member functions

[

virtuel

Original:

virtual

The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

]

Détruit l'objet exception

Original:

destructs the exception object

The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.


(function membre virtuelle publique de std::exception) [edit]

[

virtuel

Original:

virtual

The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

]

retourne une chaîne explicative

Original:

returns an explanatory string

The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.


(function membre virtuelle publique de std::exception) [edit]

Exemple

#include <iostream>
#include <new>

int main()
{
    try {
        while (true) {
            new int[100000000ul];
        }
    } catch (const std::bad_alloc& e) {
        std::cout << "Allocation failed: " << e.what() << '\n';
    }
}

Résultat :

Allocation failed: std::bad_alloc

Voir aussi