C
cai
If I am deleting a pointer to an object, excption occurs, what will happen?
If I am deleting a pointer to an object, excption occurs, what will happen?
Jack said: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 said: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).
Before 'exception-d' is thrown, you can use the standard library
uncaught_exception() to find out whether context-1 or context-2 applies,
i.e. uncaught_exception() returns true if an exception has been thrown but
hasn't yet been caught.
Rolf Magnus said: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.
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.