C++ 新庫 - bad_array_new_length



描述

這是一個關於陣列長度錯誤的異常。

以下是 std::bad_array_new_length 的宣告。

		
class bad_array_new_length;

引數

返回值

異常

不丟擲保證 - 此成員函式從不丟擲異常。

資料競爭

示例

以下為 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';
   }
}

輸出應如下所示:

It will throw an exception error
new.htm
廣告

© . All rights reserved.