473,387 Members | 1,512 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Will delete operator throw any exception?

cai
If I am deleting a pointer to an object, excption occurs, what will happen?
Jul 19 '05 #1
5 13109
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
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
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

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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: arun gunda | last post by:
I want to throw exception dynamically. This what I want to do For example I want to throw System.Net.WebException exception. I will know the full exception name at run time, can I create a...
14
by: A | last post by:
Hi, Consider this: char* ptr = "a string"; Is ptr a pointer to a dynamically created object for which i must use the delete operator to deallocate memory? I'm sure the "a string" part...
3
by: Kerri | last post by:
Hi, I am new to .NET In my Error Logic on my Aspx pages when an error happens it hits my catch statement where I throw an Exception. My question is : what is the difference between Thwo...
3
by: Ryan Liu | last post by:
Hi, In the .NET Framework SDK documentation, I can see DataRow.AcceptChanges method will throw RowNotInTableException exeception. And in DataTable.AcceptChanges(), the documentation does not...
10
by: =?iso-8859-1?q?Ernesto_Basc=F3n?= | last post by:
I am implementing my custom smart pointer: template <typename T> class MySmartPtr { public: MySmartPtr(T* aPointer) { mPointer = aPointer; }
5
by: siddhu | last post by:
What happens when deletion falis?Does operator delete function throw exception? I assume that nothrow is not available with delete. Or is it available?
1
by: =?Utf-8?B?TVIgRQ==?= | last post by:
This may seem like a stupid question but in C#: Say for instance I have a set of SQL processes that I run via ExecuteReader(). These processes return several pieces of information to the...
12
by: Premal | last post by:
Hi, I tried to make delete operator private for my class. Strangely it is giving me error if I compile that code in VC++.NET. But it compiles successfully on VC++6.o. Can anybody give me inputs...
4
by: George2 | last post by:
Hello everyone, In Bjarne's book, it is mentioned that sort of STL may throw exception, like sorting elements in a vector. In what situation will sort throw exception? I can not find a case....
2
by: kapilkumawat | last post by:
I have an requirement to overload the delete operator in C++, but it should also accept the sizeof() the object that is to be deleted. Actually I am trying to built a custom memory allocator and...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.