ex.what() changes in nested try-catch
<p>I have a nested try-catch code like below:</p>

<pre><code>void A()
{
    try
    {
        //Code like A = string(NULL) that throws an exception
    }
    catch(std::exception&amp; ex)
    {
        cout&lt;&lt;"in A : " &lt;&lt; ex.what();
        throw ex;
    }
}

void B()
{
   try
   {
       A();
   }
   catch(std::exception&amp; ex)
   {
       cout&lt;&lt;"in B : " &lt;&lt; ex.what();
   }
}
</code></pre>

<p>After running this I got this result:</p>

<pre><code>in A: basic_string::_M_construct null not valid
in B: std::exception
</code></pre>

<p>As you can see, <code>ex.what()</code> works OK in function A and tell me the correct description, but in B <code>ex.what()</code> tells me just <code>std::exception</code>. Why does this happen?</p>

<p>Am I throwing something different or wrong in the catch clause of function A? How do I throw a nested exception so that I can get the exact exception description in B?</p>