Nouvelle bibliothèque C ++ - bad_array_new_length

La description

Il s'agit d'une exception en cas de mauvaise longueur de tableau.

Voici la déclaration pour std :: bad_array_new_length.

class bad_array_new_length;

Paramètres

aucun

Valeur de retour

aucun

Exceptions

No-throw guarantee - cette fonction membre ne lève jamais d'exceptions.

Courses de données

aucun

Exemple

Dans l'exemple ci-dessous pour std :: bad_array_new_length.

#include <iostream>
#include <exception>
#include <new>

int main() {
   try {
      int* p = new int[-1];
   } catch (std::bad_array_new_length& e) {
      std::cerr << "bad_array_new_length caught: " << e.what() << '\n';
   } catch (std::exception& e) {
      std::cerr << "some other standard exception caught: " << e.what() << '\n';
   }
}

La sortie devrait être comme ça -

It will throw an exception error