`noexcept` 지정자는 C++11로부터 도입된 키워드로, 함수나 연산자가 예외(exception)를 던지지 않음을 나타내는 데 사용된다.
이는 기존의 `throw()`의 업그레이드 버전이라고 생각하면 된다.
void func1() noexcept; // do not throw
void func2() noexcept(true); // do not throw
void func3() throw(); // do not throw
void func4() noexcept(false); // may throw
단, `noexcept`를 사용할 때 주의해야 할 점은 만약 이와 같이 선언된 함수에서 예외가 발생하면 `std::terminate`가 호출되어 프로그램이 비정상적으로 종료될 수 있다.
이는 `throw()`와 마찬가지로 다음과 같은 구문을 막지 않는다.
#include <iostream>
void f2(void) throw(int)
{
throw 3;
}
void f1(void) noexcept
{
f2();
}
int main(void)
{
f1();
return 0;
}
[C++11] ref-qualified member functions(참조 한정 멤버 함수) (0) | 2023.08.23 |
---|---|
[C++11] Trailing return types (0) | 2023.08.23 |
[C++11] char32_t & char16_t (0) | 2023.08.23 |
[C++11] raw string literals (0) | 2023.08.23 |
[INFO] Modern C++ 시작하며 (0) | 2023.08.14 |