This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
[970929] Can't throw in constructor (fwd)
- To: egcs at cygnus dot com
- Subject: [970929] Can't throw in constructor (fwd)
- From: Chip Salzenberg <chip at rio dot atlantic dot net>
- Date: Mon, 6 Oct 1997 23:24:20 -0400 (EDT)
- Reply-To: chip at pobox dot com
Something else my test shows: Even when it "runs" per H.J.'s
experience, it doesn't do the thing that the test was designed to
show: When a constructor in a new expression throws an exception, the
corresponding operator delete should be called to reclaim the memory
used by the not-created-after-all object.
> -----------------------------------------------------------------------
> #include <iostream.h>
> #include <sys/types.h>
>
>
> char x[100];
> class Noisy {
> public:
> Noisy() { throw "Aaaaah!"; }
>
> void * operator new (size_t)
> { cout << "Noisy::new" << endl; return x; }
> void operator delete (void *, size_t)
> { cout << "Noisy::delete" << endl; }
> };
>
> void
> foo()
> {
> Noisy *p = 0;
> try {
> p = new Noisy;
> delete p;
> }
> catch (...) {
> cout << "Can't be noisy" << endl;
> }
> }
>
> main()
> {
> foo();
> }
> -----------------------------------------------------------------------
--
Chip Salzenberg - a.k.a. - <chip@pobox.com>
"He's Mr. Big of 'Big And Tall' fame." // MST3K