Re: why it is wrong to say: throw std::exception("error msg");
Andrew wrote:
I hope that some kind person will post chapter and verse for why it is
wrong to say:
throw std::exception("some error text");
I know it's morally wrong. I always throw a derived class myself. But
I have come across some legacy code that does this on a project I am
working on. It was drawn to my attention because I tried compiling
with gcc rather than the Microsoft Visual Studio compiler. gcc barfs,
saying that there is not suitable constructor. Quite logical IMO. The
derived classes have the ctor that's needed.
It looks like studio has a constructor that it allowing it to compile.
Or maybe its a compiler bug (there are so many). I don't know and I
don't care why studio lets it through. I need an argument for why the
legacy code should be corrected^H^H^H^H^H^H^H^H^Hchanged. A snippet
from the std would be ideal.
ISO/IEC 14882:2003
18.6.1 Class exception
namespace std {
class exception {
public:
exception() throw();
exception(const exception&) throw();
exception& operator=(const exception&) throw();
virtual ?exception() throw();
virtual const char* what() const throw();
};
}
The class simply doesn't have a constructor taking a string argument.
--
Seungbeom Kim
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]