By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,943 Members | 1,890 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,943 IT Pros & Developers. It's quick & easy.

Will delete operator throw any exception?

P: n/a
cai
If I am deleting a pointer to an object, excption occurs, what will happen?
Jul 19 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
On Sat, 5 Jul 2003 11:12:09 +0800, "cai" <al********@asus.com.cn>
wrote in comp.lang.c++:
If I am deleting a pointer to an object, excption occurs, what will happen?


There is something wrong with your code. If you are looking at it and
can't see the problem, how do you expect anyone else to find it
without seeing the code?

Most likely possibilities are:

Using delete[] on a pointer allocated with new.

Using delete on a pointer allocated with new[].

Deleting the same pointer more than once.

Deleting a pointer that was never allocated.

Deleting a pointer that was changed after it was allocated.

Writing past the end of allocated memory.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++ ftp://snurse-l.org/pub/acllc-c++/faq
Jul 19 '05 #2

P: n/a
Jack Klein wrote:
On Sat, 5 Jul 2003 11:12:09 +0800, "cai" <al********@asus.com.cn>
wrote in comp.lang.c++:
If I am deleting a pointer to an object, excption occurs, what will
happen?
There is something wrong with your code. If you are looking at it and
can't see the problem, how do you expect anyone else to find it
without seeing the code?


I think the OP asked what happens if an exception is thrown during a
delete, probably by the destructor.
Anyway, throwing in a destructor is best avoided.
Most likely possibilities are:

Using delete[] on a pointer allocated with new.

Using delete on a pointer allocated with new[].

Deleting the same pointer more than once.

Deleting a pointer that was never allocated.

Deleting a pointer that was changed after it was allocated.

Writing past the end of allocated memory.


None of those have anything to do with exceptions.
They just invoke undefined behavior (though that might also be throwing
an exception).

Jul 19 '05 #3

P: n/a
On Sat, 05 Jul 2003 10:31:22 +0200, Rolf Magnus <ra******@t-online.de>
wrote in comp.lang.c++:
Jack Klein wrote:
On Sat, 5 Jul 2003 11:12:09 +0800, "cai" <al********@asus.com.cn>
wrote in comp.lang.c++:
If I am deleting a pointer to an object, excption occurs, what will
happen?


There is something wrong with your code. If you are looking at it and
can't see the problem, how do you expect anyone else to find it
without seeing the code?


I think the OP asked what happens if an exception is thrown during a
delete, probably by the destructor.
Anyway, throwing in a destructor is best avoided.
Most likely possibilities are:

Using delete[] on a pointer allocated with new.

Using delete on a pointer allocated with new[].

Deleting the same pointer more than once.

Deleting a pointer that was never allocated.

Deleting a pointer that was changed after it was allocated.

Writing past the end of allocated memory.


None of those have anything to do with exceptions.
They just invoke undefined behavior (though that might also be throwing
an exception).


You're right, I misread the question (or misthought). Must still be
dazzled by tonight's fireworks display. Thanks for the correction.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++ ftp://snurse-l.org/pub/acllc-c++/faq
Jul 19 '05 #4

P: n/a

Klaus Eichner wrote:
[...]
Before 'exception-d' is thrown, you can use the standard library
uncaught_exception() to find out whether context-1 or context-2 applies,
That won't necessarily work. The current uncaught_exception() is
totally brain-damaged. What's really needed is something ala "bool
std::unwinding<T>(T *) throw()" or something like that.

http://groups.google.com/groups?selm...708D0%40web.de
(Subject: Re: Alexandrescu on error handling at ACCU conference 2002)
i.e. uncaught_exception() returns true if an exception has been thrown but
hasn't yet been caught.


Stay away from uncaught_exception(). To the OP: make your dtor
throw()-nothing (add empty ES) and see what will happens. Note that
the upcoming C++ standard is likely to impose the implicit throw()-
nothing ES on ALL dtors. Be aware.

regards,
alexander.
Jul 19 '05 #5

P: n/a
cai

"Rolf Magnus" <ra******@t-online.de>
??????:be*************@news.t-online.com...
Jack Klein wrote:
On Sat, 5 Jul 2003 11:12:09 +0800, "cai" <al********@asus.com.cn>
wrote in comp.lang.c++:
If I am deleting a pointer to an object, excption occurs, what will
happen?


There is something wrong with your code. If you are looking at it and
can't see the problem, how do you expect anyone else to find it
without seeing the code?


I think the OP asked what happens if an exception is thrown during a
delete, probably by the destructor.
Anyway, throwing in a destructor is best avoided.


Yes, that is what I mean. I am afraid that if delete will throw exception or
not, just like new ?
Jul 19 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.