 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Ganesh Guest
|
Posted: Thu Aug 24, 2006 4:17 pm Post subject: questions on placement delete called after an exception. |
|
|
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
|
Posted: Fri Aug 25, 2006 3:46 pm Post subject: Re: questions on placement delete called after an exception. |
|
|
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
|
Posted: Mon Aug 28, 2006 4:17 pm Post subject: Re: questions on placement delete called after an exception. |
|
|
===================================== 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
|
Posted: Wed Sep 06, 2006 4:14 pm Post subject: Re: questions on placement delete called after an exception. |
|
|
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 |
|
 |
|
|
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
|
|