Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Generic exception classes ?

Generic exception classes ?

Scheduled Pinned Locked Moved C / C++ / MFC
algorithmsregexjsonhelpquestion
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Mr Brainley
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups