C++内存分配异常处理
来源:互联网 发布:软件开发书籍 编辑:程序博客网 时间:2024/04/29 19:52
在内存分配失败的情况下,new会抛出bad_alloc的异常,而malloc会返回空指针。
try { int* a = new int[8000000000];cout << "get memory" << endl; } catch(bad_alloc& ba) {cout << "catch the exception" << endl; }
b. malloc异常处理:
int* a = (int*)malloc(8000000000);if(NULL == a){cout << "alloc memory failed" << endl;}
c. new也可以通过判断返回值处理异常
int* a = new(std::nothrow)int[8000000000];if(NULL == a){cout << "alloc memory failed" << endl;}
- C++内存分配异常处理
- C++ new分配内存时的std::bad_alloc异常处理
- 内存分配失败处理
- 内存处理与分配
- C语言的内存分配和段错误的处理
- c/C++内存分配
- C内存分配
- C语言内存分配
- C/C++内存分配
- C/C++内存分配
- c内存分配
- C/C++内存分配
- C程序内存分配
- c 内存分配
- C语言内存分配
- C内存分配
- C的内存分配
- c语言内存分配
- JSP和Servlet面试题精选
- iframe 和 jquery
- 关于GAE/J下的JDO关系(Relationships)
- 优先级队列 + 迪斯拉算法
- cookies 的操作
- C++内存分配异常处理
- Spring AOP
- 处理表重复记录(查询和删除)
- 国米OUT,意甲酱油了
- HDOJ-Monkey and Banana-动态规划
- [转载]C#中使用WindowsSDK
- Ubuntu下django安装
- FW:Reverse a Singly Linked List Recursively in Java
- 用ssh在虚拟机与宿主机之间传送文件的一些问题