Skip to content

Latest commit

 

History

History
55 lines (40 loc) · 2.11 KB

File metadata and controls

55 lines (40 loc) · 2.11 KB
title nothrow (C++) | Microsoft Docs
ms.custom
ms.date 01/03/2018
ms.reviewer
ms.suite
ms.technology
cpp-language
ms.tgt_pltfrm
ms.topic language-reference
f1_keywords
nothrow_cpp
dev_langs
C++
helpviewer_keywords
__declspec keyword [C++], nothrow
nothrow __declspec keyword
ms.assetid 0a475139-459c-4ec6-99e8-7ecd0d7f44a3
author mikeblome
ms.author mblome
manager ghogen
ms.workload
cplusplus

nothrow (C++)

Microsoft Specific

A __declspec extended attribute which can be used in the declaration of functions.

Syntax

return-type __declspec(nothrow) [call-convention] function-name ([argument-list])

Remarks

We recommend that all new code use the noexcept operator rather than __declspec(nothrow).

This attribute tells the compiler that the declared function and the functions it calls never throw an exception. However, it does not enforce the directive. In other words, it never causes std::terminate to be invoked, unlike noexcept, or in std:c++17 mode (Visual Studio 2017 version 15.5 and later), throw().

With the synchronous exception handling model, now the default, the compiler can eliminate the mechanics of tracking the lifetime of certain unwindable objects in such a function, and significantly reduce the code size. Given the following preprocessor directive, the three function declarations below are equivalent in /std:c++14 mode:

#define WINAPI __declspec(nothrow) __stdcall

void WINAPI f1();
void __declspec(nothrow) __stdcall f2();
void __stdcall f3() throw();

In /std:c++17 mode, throw() is not equivalent to the others that use __declspec(nothrow) because it causes std::terminate to be invoked if an exception is thrown from the function.

The void __stdcall f3() throw(); declaration uses the syntax defined by the C++ standard. In C++17 the throw() keyword was deprecated.

END Microsoft Specific

See also

__declspec
noexcept
Keywords