- 컴파일 타임에 해당 표현식이 예외를 던지지 않는 표현식인지 체크하여, true/false를 반환한다.
- 예외가 없음을 명시하고 체크 가능하게 하는 기능.
void foo() noexcept
{
}
int main()
{
// 이런식으로 noexcept 함수인지 검사할 수 있다.
bool b = noexcept ( foo() );
}
추가 정보
- 예외가 없는 함수는 컴파일러 최적화가 더욱 잘 된다.
- move 생성자(대입연산자)는 되도록 예외를 던지지 않게 만들고 "noexcept" 를 붙이는 것이 좋다.
- 많은 라이브러리들이 noexcept여부를 검사하여 최적화된 처리를 할 수 있기 때문에.
- 소멸자는 default 로 noexcept 이다.
- 맴버변수의 복사생성자 등등이 noexcept가 있는지 없는지에 따라 default 함수들의 noexcept 여부가 달라진다.
- 생성자는 생성중 예외가 발생하면 커스텀 생성자의 경우 커스텀 소멸자가 호출된다.