如何判断new的内存是否失败?使用try catch
来源:互联网 发布:淘宝开通充值平台 编辑:程序博客网 时间:2024/05/17 02:28
#include<stdlib.h>#include<stdio.h>#include<exception>#include<iostream>#include<new>using namespace std;int main(){ try { while(1) { //char *p = (char*)malloc(1000000*sizeof(char)); char *p = new char[1000000]; if(!p) break; else printf("malloc 1M\n"); } //free(p); }catch(const bad_alloc& e) { cout<<e.what()<<endl; cout<<"new exception\n"; }catch(const exception& e) { cout<<e.what(); cout<<"other exception\n"; }}
- 如何判断new的内存是否失败?使用try catch
- try catch与new Error()的使用
- 用if还是try catch来判断内存分配失败
- 使用try catch判断是否输入为数字
- 后台判断格式是否想要的类型可使用 try{} catch{}捕获错误,
- php的try catch如何正确使用?
- try catch 的使用
- try...catch的使用
- 如何使用try catch throw
- 【恶搞】如何在Unity正确的使用try-catch
- JS try.....catch的使用
- JS try.....catch的使用
- JS try.....catch的使用
- JS try.....catch的使用
- try-catch-finally的使用
- try...catch的简单使用
- Java try . catch 的使用
- iOS try catch的使用
- Ubuntu Server 命令行下的默认语言改为英语en_US.UTF-8
- 让不懂编程的人爱上iPhone开发(2013春iOS6版)-开篇
- Android工程Debug证书过期解决方案 -- eclipse
- unity3d优化DrawCall
- Activity转换——intent、Bundle
- 如何判断new的内存是否失败?使用try catch
- js去数组重复数据
- CountDownLatch,FutureTask,Semaphore,Barrier,Exchanger
- 如何成为强大的程序员?
- MFC消息路由/映射机制研究
- netlink instruction
- 进一步对C语言的文件理解
- UIAlertView选择
- Android-x86虚拟机安装配置全攻略