Question: Focusing on Visual C++, have you ever experienced significant performance gains in C++ code using `throw()` (i.e. `__declspec(nothrow)`) non-throwing specification?
Does it really help the optimizer?
Are there any benchmarks showing performance gains?

I found different (opposite) advice on the Internet:

[Boost exception-specification rationale](http://www.boost.org/development/requirements.html#Exception-specification) is *against* `throw()`, instead Larry Osterman seems to be *in favor* of it in his blog post: [Why add a throw() to your methods?](http://blogs.msdn.com/b/larryosterman/archive/2006/03/22/558390.aspx)

(I'd like to clarify that **I'm interested in VC++ specific code**; I know that in GCC the `throw()` specification can actually be a "pessimization" due to run-time checks.)

**P.S.** Reading ATL headers, I found that `throw()` is used pervasively; moreover, I found a convenient C++ RAII `unique_handle` class in [this MSDN article](http://msdn.microsoft.com/en-us/magazine/hh288076.aspx) that uses `throw()` specification as well.

Answer: 
The MSVC compiler treats it as an optimization hint, yes.

Boost has to be cross-platform, they have to go for something that's safe and efficient on a variety of compilers. And as the boost docs say, *some* compilers might generate slower code when `throw()` is specified, and in many cases, compilers can deduce that no exception is thrown *regardless* of whether there is a `throw()` specification, so for Boost, the safest approach is to just never use throw-specifications.

But if you're targeting MSVC specifically, then `throw()` effectively tells the compiler not to generate exception-handling code for the function, which may give a speedup in cases where the function was too complex for the compiler to determine that no exception could be thrown.
Main problem with `throw()` is that code inside function marked as `throw()` *can* throw.
For example, this will work perfectly:

```
void foo() throw()
{
    throw "haha\n";
}

int main()
{
    try {
        foo();
    }
    catch(const char* s) {
        std::cout << s;
    }
    return 0;
}

```

Note, that foo would not `throw` to `main`, of cause. And you will not catch the exception (as if you comment `throw()` specifier). Instead, compiler will wrap code function with `try{}catch()` block. When exception is generated it will be handled by global handler (that will mean your program crash by default).

Note, that compiler *have to* wrap function code with `try{}cath()` block, unless compiler is sure, that inner code has no possibility to generate exception. 

As a result, some optimization with the *caller* of `foo` can be done, but things get more complex *inside* `foo`.

**EDIT:**

Things with `__declspec(nothrow)` is different: As [Microsft tells](http://msdn.microsoft.com/en-us/library/49147z04%28v=vs.71%29.aspx), 

> 
> This attribute tells the compiler that the declared function **and the
>  functions it calls** never throw an exception.
> 
> 
> 

It means, that compiler can omit `try{}catch()` wrapper code.

**EDIT2**
Actually, Microsoft violates standard behavior and does not generate warpper for `throw()`. Well, then you can use `throw()` to improve performance.