Skip to content

Instantly share code, notes, and snippets.

@russleyshaw
Created August 12, 2016 20:30
Show Gist options
  • Save russleyshaw/c201248b32b9faa75cd4b586c419d1d3 to your computer and use it in GitHub Desktop.
Save russleyshaw/c201248b32b9faa75cd4b586c419d1d3 to your computer and use it in GitHub Desktop.
//Macro for simple base and inherited exception creation
#ifndef _EASY_EXCEPTION_H
#define _EASY_EXCEPTION_H
#include <exception>
#define EASY_EXCEPTION(NAME, WHAT) \
class NAME: public std::exception { \
public: \
virtual const char* what() const noexcept { return WHAT; } \
};
#define EASY_INHERIT_EXCEPTION(NAME, BASE, WHAT) \
class NAME: public BASE { \
public: \
virtual const char* what() const noexcept { return WHAT; } \
};
#endif
@russleyshaw
Copy link
Author

Example of usage

class ObjData {
    public:
        EASY_EXCEPTION(Exception, "Exception");
        EASY_INHERIT_EXCEPTION(FileException, Exception, "FileException")

        std::vector< Point3D<float> > vertices;

        static ObjData loadFile(const std::string& filename);
    };

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment