◐ Shell
clean mode source ↗

std::bad_alloc - cppreference.com

De cppreference.com

<metanoindex/>

<tbody> </tbody>

Definido no cabeçalho

<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

Funções de membro

constructs the bad_alloc object
(função pública membro)
replaces a bad_alloc object
(função pública membro)

Retorna a string explicativo

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.


(função pública membro)

Herdado de std::exception

Member functions

destrói o objeto de exceção

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.


(of std::exception função pública virtual membro) [edit]

retorna uma cadeia explicativa

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.


(of std::exception função pública virtual membro) [edit]

Exemplo

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

Saída:

Allocation failed: std::bad_alloc

Veja também