Why does std :: exception contain additional constructors in VC ++?

What I noticed 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 on 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 seems that the Microsoft version allows you to specify an error message for the exception object, while the standard version allows you to do this only for derived classes (but does not prevent you from creating a general exception with the message undefined).

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

+24
c ++ standards visual-c ++
Mar 01 '11 at 16:20
source share
2 answers

There is really no good reason. The MS implementation decided to put the string processing in std :: exception, and not in every class received from it (<stdexcept>).

Since they actually also provide the interface required by the standard, this can be seen as an appropriate extension. Programs following the standard work as expected.

Other implementations do not do this this way, therefore portable programs should not use additional constructors.

+18
Mar 01 2018-11-11T00:
source share

Getting rid of the throw specification was a good idea. Although they should not be dropped, dropped specifications are generally bad.

Inserting the extensions will make the code not portable, but it will most likely fix the slice problems, where people "catch" std :: exception by value and can copy the line locally from what it copies.

I see no advantage in int or implicit constructors that take a single parameter.

0
Mar 01 '11 at 16:35
source share



All Articles