"Ney André de Mello Zunino" <> wrote in message
news:...
> Hello.
>
> Given the following try...catch construct:
>
> try
> {
> }
> catch (const string& msg)
> {
> }
>
> I might be overlooking something basic, but why can't the compiler use one
> of std::string's constructors in order to match:
>
> throw "Something happened!";
>
> The intent is to avoid having to add an extra catch block, i.e.:
>
> try
> {
> }
> catch (const string& msg)
> {
> }
> catch (const char* const msg)
> {
> }
>
> Thank you,
It is a bad practice to throw literals. It leads to code like
catch(const char *text) {
string str(text);
if (text == "error1") //...
else if (text == "error2") //...
else if (text == "error3")//...
}
|