Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

If I wanted to implement my own version of the std::exception for no good reason, are there any special things about implementing this kind of object that I should be aware of? It seems like a fairly simple thing that is mostly a string wrapper...

Here is my implementation so far:

#pragma once;

#include <string>

class MyException
    MyException(const std::wstring&);
    virtual ~MyException(){}

    virtual MyException& operator=(const MyException& rhs);
    virtual const std::wstring& what(){return msg;};

    std::wstring msg;

MyException::MyException(const std::wstring& message)

MyException& MyException::operator=(const MyException& rhs)
    if(this == &rhs)
        return *this;
    msg = rhs.msg;
    return *this;
share|improve this question

closed as off topic by gnat, Walter, Nemanja Trifunovic, Glenn Nelson, MichaelT Feb 16 '13 at 2:28

Questions on Programmers Stack Exchange are expected to relate to software development within the scope defined by the community. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about reopening questions here.If this question can be reworded to fit the rules in the help center, please edit the question.

How is this off-topic? – James Feb 16 '13 at 2:30

The best advice I could give you is to base your code on the standard exception classes. It will make your code simpler and will allow you and your users to interact with existing code, the standard library or third party libraries.

share|improve this answer
They can't handle Unicode, whereas my direct guess would be that he's using VS and wants to deal with Unicode. – DeadMG Feb 16 '13 at 0:47

Not particularly. Exception handling is already an expensive routine, so it's difficult to cock things up from that perspective, and the language doesn't treat thrown objects notably different to any other. In fact, you could simply throw a string if you wanted to. But you should design the more derived classes to contain more information, IMO.

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.