i need some explanation about the exceptions.

Hello everyone.
i've got a several questions in my mind,but first take a look at this code:
1
2
3
4
5
6
class my_exception : public exception {
public:
    virtual const char* what() const throw() {
        return "my exception occured";
    }
}

here's my questions:
1-)why does the what() method returns (const char*)?
2-)what does the (const) keyword after the method name does?
3-)what is the purpose of adding throw() before the opening brace?
Last edited on
1-)why does the what() method returns (const char*)?

So you can use the returned string to tell the user what went wrong.

2-)what does the (const) keyword after the method name does?

It's a promise not to change any class member variables that aren't marked mutable

3-)what is the purpose of adding throw() before the opening brace?

It's a promise that this function won't throw anything; an exception specification. It's a bad idea and considered bad practice.
https://stackoverflow.com/questions/1055387/throw-keyword-in-functions-signature
Topic archived. No new replies allowed.