Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8793597
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T23:08:32+00:00 2026-06-13T23:08:32+00:00

I have tried a simple C++ CException implementation class, deriving from std::exception. What did

  • 0

I have tried a simple C++ CException implementation class, deriving from std::exception. What did I do wrong, what should I add more, what should I improve on? What is it more to c++ exceptions that one should take into consideration? The aim is to make it as much platform independent as possible. The code follows:
Edited:

class CeException: public std::exception {
public:
    char* getascii(const wchar_t* msg)
    {
        char* pasc = new char[wcslen(msg) + 1 ];
        wcstombs(pasc, msg, wcslen(msg) + 1);
        return pasc;
    }
    CeException(const wchar_t* msg, char* pasc = NULL ):
    exception(pasc = getascii(msg))
    {

        delete[] pasc;
    }
    CeException(const string msg) 
    {   

    }
    virtual ~CeException()
    {       
    }
    BOOL GetErrorMessage(LPTSTR lpszError, UINT nMaxError, PUINT pnHelpContext = NULL )
    {

        const char* pasc = this->what();

        wchar_t* puni = new wchar_t[strlen(pasc)+1];
            mbstowcs(puni,pasc, strlen(pasc) + 1);

        wcscpy_s(lpszError,nMaxError, puni);
        delete[] puni;
        return 0;
    }
    void Delete()
    {
        delete this;
    }


};

I have edited with my final implementation, using your indications.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T23:08:32+00:00Added an answer on June 13, 2026 at 11:08 pm

    Typically you don’t need to implement methods inside exception class, so it might look something like this:

    class YourException : public std::runtime_error
    {
    public:
        explicit YourException(const std::string & msg) :
            std::runtime_error(msg)
        {
        }
    };
    

    I don’t understand the reasons to have other methods.

    You should not throw exception from it’s constructor. Instead, client code should throw your exception:

        throw YourException("Some error");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This should be really simple, but I have tried many solutions posted on the
I am currently learning F# and have tried (an extremely) simple example of FizzBuzz.
I have tried to create a simple controller/model (based on the samples code of
I have tried to boil this down to a simple example to demonstrate what
I have started using Simple-form and Bootstrap and I have tried to follow this
I have created a small and simple android app. I tried installing it on
I have a method which does a simple mysql insert, when I tried to
I have done this simple catch: try { echo Request::factory() ->execute() ->send_headers() ->body(); }catch(Exception
I have a simple question about sending a file (XML file) from my webapp
I have a simple file transfer application, which transfers 4096 bytes per write from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.