Q:

virtual method in exceptions

I have made my own exception class which derives from runtime_error and is getting an int in the c'tor. 
I would like to make a base class for this exception, in order to use polymorphism, so I could catch only the base class and basically I would be catching the derived class, and then call .what() method from it. 
So, this is the base class: (ofc in another cpp file I got baseException::~baseException(){})
class baseException
{
    virtual ~baseException()=0 {}
    virtual const char* what()=0;
};

And this is the derived class:
class myException: public runtime_error, public baseException
{
public:
    myException(int): runtime_error("Error occured") {}
    const char* what() {return runtime_error::what();}
};

But when in the main I write:
catch(baseException* x)
{
cout<<x->what();
}

it just skips it and does not enter the block, even though myException inherits from baseException.  Any suggests? 

A:

Your catching a reference to a baseException object; therefor you just know the methods of that class.  baseException does not have a member called what() though.  This causes the error. 
Make baseException derive from runtime_error or catch a myException directly. 
Edit:
This snippet shows that theres absolutely no reason why pointers shouldnt work together with exceptions:
#include <iostream>
#include <string>

class A {
public:
    virtual int test() = 0;
};

class B : public A {
public:
    virtual int test() {
        return 42;
    }
};

int _tmain(int argc, _TCHAR* argv[])
{
    try {
        throw new std::string("foo");
    } catch (std::string* ecx){
        std::cout << *ecx << std::endl;
    }

    try {
        throw new B();
    } catch (A* ecx) {
        std::cout << ecx->test() << std::endl;
    }
}

Output:

foo
42

