Best Exception handling practice

Today I was starting with SDL, and in their wiki under the SDL_Init() function page there was this example:

1
2
3
4
5
6
7
8
9
10
11
12
13
#include <exception>
#include <string>
#include "SDL.h"

class InitError: public std::exception {
    public:
        InitError();
        InitError(const std::string&);
        virtual ~InitError() throw();
        virtual const char* what() const throw();
    private:
        std::string msg;
};


So I never did exception handling and didn't knew the meaning of that throw() in the member function declaration.
I checked here on the site -> http://www.cplusplus.com/doc/tutorial/exceptions/
and it says
Exception specification
Older code may contain dynamic exception specifications. They are now deprecated in C++, but still supported. A dynamic exception specification follows the declaration of a function, appending a throw specifier to it.


So I don't want to go and practice on deprecated code, can someone more experienced about current C++ show me an example of how the example above would be properly done?
Last edited on
C++17 removed dynamic exception specification completely, but kept "throw()", because so much existing code uses it, redefined as deprecated exact synonym of "noexcept". If you feel like updating that example, just use noexcept instead -- http://en.cppreference.com/w/cpp/language/noexcept_spec
Last edited on
Thanks Cubbi :)
Topic archived. No new replies allowed.