std::nothrow

Reference : http://www.cprogramming.com/tips/tip/cincrement-new-does-not-return-0-on-failure

C++ new는 할당실패시 bad_alloc exception을 던진다.
매번 try-catch 하기 귀찮으니까, malloc()처럼 오류상황에서 0을 리턴하게 만들고 싶은 경우, 다음과 같이 고친다.

#include <new>
...
type_t *ptr = new (std::nothrow) type_t[size];
...

답글 남기기

이메일 주소는 공개되지 않습니다. 필수 필드는 *로 표시됩니다