Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does std::exception have extra constructors in VC++?

Something I noticed just now. Definition of exception in the standard (18.6.1):

class exception {
public :
    exception() throw();
    exception(const exception &) throw();
    exception& operator=(const exception&) throw();
    virtual ~exception() throw();
    virtual const char* what() const throw();
};

Definition of exception in MSDN:

class exception {
public:
   exception(); 
   exception(const char *const&);
   exception(const char *const&, int);
   exception(const exception&); 
   exception& operator=(const exception&); 
   virtual ~exception();
   virtual const char *what() const;
};

It would seem that Microsoft's version allows you to specify the error message for an exception object, while the standard version only lets you do that for the derived classes (but doesn't prevent you from creating a generic exception with an undefined message).

I know this is pretty insignificant, but still. Is there a good reason for this?

like image 990
suszterpatt Avatar asked Mar 01 '11 16:03

suszterpatt


1 Answers

Not really any good reason. The MS implementation has chosen to put the string handling in std::exception instead of in each class derived from it (<stdexcept>).

As they actually also provide the interface required by the standard, this can be seen as a conforming extension. Programs following the standard works as expected.

Other implementations do not do it this way, so portable programs should not use the extra constructors.

like image 181
Bo Persson Avatar answered Oct 18 '22 09:10

Bo Persson