I expected A::~A() to be called in this program, but it isn't:
#include <iostream>
struct A {
~A() { std::cout << "~A()" << std::endl; }
};
void f() {
A a;
throw "spam";
}
int main() { f(); }
However, if I change last line to
int main() try { f(); } catch (...) { throw; }
then A::~A() is called.
I am compiling with "Micr...
I need to get the stack information of my C application in certain points. I've read the documentation and searched the Net but still cannot figure out how I can do it. Can you point to a simple process explanation? Or, even better, to an example of stack unwinding. I need it for HP-UX (Itanium) and Linux.
Thanks
...
Hi,
I have a c++ code, I use MSC9 to compile it.
It keeps crashing randomly. For example it crashes if it is called from Perl using `` but it does not crash when It is called from command line or from Ultimate++.
I mean calling it from perl eg. f.exe arg1 arg2 arg3
Stack trace does not show much. Tracing the program line by line proved...
Okay I go through 2 layers of functions fun1 calls func2 calls func3 . I pass a pointer all the way down using basically int *ptr, at the lowest "level" of the call stack I also have another function that dynamically allocates memory for an int array. At the top level (func1 level) I always get null back for the passed pointer. I have tr...
I heard people say exception handling is a bit expensive because of the stack unwinding.
I don't get something, the stack unwinding happens whether I throw an exception and whether I use "return". So where is the difference?
If for example I get a memory problem that I can't handle - the only option is to stop the function till the I r...
While answering this question I noticed that I got the following dialog while atempting to move the "cursor" while an exception was being handled:
Unable to set the next statement to this location. The attempt to unwind the callstack failed.
Unwinding is not possible in the following scenarios:
Debugging was started via ...
As far as I know, in case of an uncaught exception, C++ destroys the local variables immediately, Java releases the references and leaves the rest for the garbage collector.
Is this right? What exactly is the difference between Java and C++ on this issue? in other words, which of these two languages is considered better in terms of stac...
C++ automagically calls destructors of all local variables in the block in reverse order regardless of whether the block is exited normally (control falls through) or an exception is thrown.
Looks like the term stack unwinding only applies to the latter. How is the former process (the normal exit of the block) called concerning destroyi...
Just curious if my destructors are being called.
(Specifically for Visual Studio, when you hit the red stop button)
...
Suppose you have created an instance of a Window class. The window is shown to the user. Then, an exception is thrown, and reference to the instance is lost, but the window is still seen by the user because the instance still exists (it's just not referenced anymore).
What to do in these circumstances?
I'm specifically talking about th...
I recently stumbled into this this C++/Lua error
int function_for_lua( lua_State* L )
{
std::string s("Trouble coming!");
/* ... */
return luaL_error(L,"something went wrong");
}
The error is that luaL_error use longjmp, so the stack is never unwound and s is never destructed, leaking memory. There are a few more Lua API's th...
I have a simple C++ object that I create at the start of function F() to ensure two matched functions (OpDo, OpUndo) are called at the start and return of the F(), by using the object's constructor and destructor. However, I don't want the operation to be undone in case an exception was thrown within the body of F(). Is this possible to ...