C++ throw dereferenced pointer
<p>What is the type of the exception object in the following thrown:</p>

<p>Question1> <code>range_error r("error"); throw r;</code></p>

<p>Answer1>   an object of range_error</p>

<p>Question2> <code>exception *p = &amp;r; throw *p;</code></p>

<p>Answer2>   a sliced object of exception</p>

<p>Question3> <code>exception *p = &amp;r; throw p;</code></p>

<p>Answer3>   a pointer pointing to range_error is thrown. The capture-handling can access the range_error member functions through dynamic binding.</p>

<p>Do I get these question right?</p>

<p>// Updated and Compiled and Run on VS2010</p>

<pre><code>#include &lt;iostream&gt;
using namespace std;

class ExClassA
{
public:
    virtual void PrintMe() const
    {
        cout &lt;&lt; "ExClassA" &lt;&lt; endl;
    }
};

class ExClassB : public ExClassA
{
public:
    virtual void PrintMe() const
    {
        cout &lt;&lt; "ExClassB" &lt;&lt; endl;
    }
};

int main(int argc, char* argv[])
{   
    ExClassB exClassB;
    ExClassA *p = &amp;exClassB;

    try
    {
        throw *p;
    }
    catch (const ExClassA&amp; e)
    {
        e.PrintMe();        
    }

    try
    {
        throw p;
    }
    catch (const ExClassA* e)
    {
        e-&gt;PrintMe();
    }
}
</code></pre>

<p>The first try-catch of above program prints "ExClassA"</p>

<p>The second try-catch of above program prints "ExClassB"</p>
