std::bad_alloc
来自cppreference.com
|
|
This page has been machine-translated from the English version of the wiki using Google Translate.
The translation may contain errors and awkward wording. Hover over text to see the original version. You can help to fix errors and improve the translation. For instructions click here. |
| Defined in header <new>
|
||
| class bad_alloc; |
||
std::bad_alloc is the type of the object thrown as exceptions by the <div class="t-tr-text">分配的功能</div> to report failure to allocate storage.
Original:allocation functionsThe text has been machine-translated via [http://translate.google.com Google Translate].
You can help to correct and verify the translation. Click [http://en.cppreference.com/w/Cppreference:MachineTranslations here] for instructions.
目录 |
[编辑] 成员函数
| constructs the bad_alloc object (公共成员函数) | |
| replaces a bad_alloc object (公共成员函数) | |
| 返回解释性字符串 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. (公共成员函数) | |
Inherited from std::exception
Member functions
| [虚拟的] </ SPAN></div></div>
|
解构异常对象 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)
|
| [虚拟的] </ SPAN></div></div>
|
返回一个说明字符串 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)
|
</div>
[编辑] 为例
#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'; } }
Output:
Allocation failed: std::bad_alloc
[编辑] 另请参阅
| 分配的功能 Original: allocation functions The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (函数) | |
