arghasen
9/20/2018 - 4:37 PM

Custom Exception

class MyException : public exception
{
    int n;
    //IMPORTANT: need this member as what needs to return const char* else returned value will be lost on scope.
    std::string m_error;
    public
    MyException(int n):n(n)
    {
        m_error = to_string(n);
    }
    const char * what () const throw ()
    {
        return  m_error.c_str();
    }
};