C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

questions on placement delete called after an exception.

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language, library and standards
View previous topic :: View next topic  
Author Message
Ganesh
Guest





PostPosted: Thu Aug 24, 2006 4:17 pm    Post subject: questions on placement delete called after an exception. Reply with quote



Consider the following code for Dummy class where constructor of Dummy
throws an exception while called with placement new:

struct Dummy {
Dummy() { throw -1;}
};

void* operator new(size_t s, int i) { }

void operator delete(void* p, int i)
{
if(std::uncaught_exception())
printf("an exception is active\n");
if (i == 1234)
exit(0);
}

The constructor throws an exception while called thro placement new,
corresponding placement delete is called. In that operator delete:
1) std::uncaught_exception() should return true or false?
2) what happens to the exception object as exit is called from that
code?

I checked [5.3.4], [3.7.3.2] and [17.4.3.4], but its not clear for me.
(Sorry if I had missed anything obvious).

Thanks!
-Ganesh

---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]
Back to top
Shooting
Guest





PostPosted: Fri Aug 25, 2006 3:46 pm    Post subject: Re: questions on placement delete called after an exception. Reply with quote



Ganesh wrote:
Quote:
Consider the following code for Dummy class where constructor of Dummy
throws an exception while called with placement new:

struct Dummy {
Dummy() { throw -1;}
};

void* operator new(size_t s, int i) { }

void operator delete(void* p, int i)
{
if(std::uncaught_exception())
printf("an exception is active\n");
if (i == 1234)
exit(0);
}

The constructor throws an exception while called thro placement new,
corresponding placement delete is called. In that operator delete:
1) std::uncaught_exception() should return true or false?

I think it should return true because there is actually a uncaught
exception

Quote:
2) what happens to the exception object as exit is called from that
code?

Destroyed I believe. Because that's the end of this process.

Quote:

I checked [5.3.4], [3.7.3.2] and [17.4.3.4], but its not clear for me.
(Sorry if I had missed anything obvious).

Thanks!
-Ganesh

---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]

---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]
Back to top
Ganesh
Guest





PostPosted: Mon Aug 28, 2006 4:17 pm    Post subject: Re: questions on placement delete called after an exception. Reply with quote



===================================== MODERATOR'S COMMENT:
Please don't quote moderation footers when replying.


===================================== END OF MODERATOR'S COMMENT

Shooting wrote:
Quote:
Ganesh wrote:
Consider the following code for Dummy class where constructor of Dummy
throws an exception while called with placement new:

struct Dummy {
Dummy() { throw -1;}
};

void* operator new(size_t s, int i) { }

void operator delete(void* p, int i)
{
if(std::uncaught_exception())
printf("an exception is active\n");
if (i == 1234)
exit(0);
}

The constructor throws an exception while called thro placement new,
corresponding placement delete is called. In that operator delete:
1) std::uncaught_exception() should return true or false?

I think it should return true because there is actually a uncaught
exception

Looks obvious, but for my surprise, compilers differ in behaviour in
this. Shouldn't be that this specific case documented in the standard?


Quote:
2) what happens to the exception object as exit is called from that
code?

Destroyed I believe. Because that's the end of this process.

Compilers differ in behaviour with this too (in few compilers, it fails
with uncaught exception and in a few it results in normal program
termination). I think the standard should explicitly mention the
behaviour.

For this difference in compiler behaviours, I raised this question, for
I wanted to know if its a compiler defect or defect in the standard (as
it doesn't specify the behaviour in these two cases).

-Ganesh

Quote:

I checked [5.3.4], [3.7.3.2] and [17.4.3.4], but its not clear for me.
(Sorry if I had missed anything obvious).

Thanks!
-Ganesh

---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]

---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]

---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]
Back to top
Guest






PostPosted: Wed Sep 06, 2006 4:14 pm    Post subject: Re: questions on placement delete called after an exception. Reply with quote

Ganesh wrote:

Quote:
1) std::uncaught_exception() should return true or false?

true :)

Quote:
2) what happens to the exception object as exit is called from that
code?

I believe that exit, after closing files and executing atexit stack,
calls abort (or something equivalent), in a purist sense would't
that be in violation of [3.7.3.2] ?

Quote:
Destroyed I believe. Because that's the end of this process.

how would that be possible other than to register it's destructor
with atexit

---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]
Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language, library and standards All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.