首页
mac
it
登录
6mi
u
盘
搜
搜 索
it
new 内存失败如何处理
new 内存失败如何处理
mac
2026-01-18
8
方法一:
try
{
//分配内存
int
*
a
=
new
int
[
bigBigNum
]
;
}
catch
(
std
::
bad_alloc
)
{
//异常处理
// 返回
}
方法二:
try
{
double
*
ptr
=
new
double
[
1000000
]
;
}
catch
(
bad_alloc
&
memExp
)
{
//失败以后,要么abort要么重分配
cout
<<
memExp
.
what
(
)
<<
endl
;
}
转载请注明原文地址: https://mac.8miu.com/read-510491.html
最新回复
(
0
)