Generic exception classes ?
-
I have a project in wich a want to map many Win32 API Errors to exception classes derived from std::runtime_error. All of these follow one pattern :
class RegCreateKeyExException : public std::runtime_error
{
public:
RegCreateKeyExException(const std::string& message, LONG lErrorCode)
: runtime_error(message)
{
}LONG getErrorCode() { return m\_lErrorCode; }
private:
LONG m_lErrorCode;
};Whenever i want to create a new class, i have to copy/paste this and just change the name. I was thinking about a way to create a class-template that generates generic exception-classes, but i found no way that wasn't ugly. Then again i'm no template crack, so maybe someone out there has an elegant solution to that problem (or the clear answer that there is none and i can stop searching). wbr Brainley