最終更新日時(UTC):
が更新

履歴 編集

class
<new>

std::bad_alloc

namespace std {
  class bad_alloc : public exception;
}

概要

何らかの理由で記憶域の動的確保に失敗するなど、get_new_handler()nullptrを返した場合に投げられる例外

メンバ関数

名前 説明 対応バージョン
(constructor) コンストラクタ
(destructor) デストラクタ
operator= 代入演算子
what エラー理由を取得する

#include <iostream>
#include <new>

struct X {};

int main()
{
  try {
    X* x = new X();
  }
  catch (std::bad_alloc& e) {
    // メモリ確保に失敗
    std::cout << e.what() << std::endl;
  }
}