am I misunderstanding exception frames
Hi,
I am getting a hard-crash while using exception frames, or so it seems
by logging to a file. The crash occurs only in release mode with full
optimization.
My exception struct:
struct VMExitException {
EStruct* pstruct; // a pointer to a struct that needs
subrefing if not null
... // other members
// inline constructor
VMExitException (EStruct* s)
{
pstruct = s;
...
}
};
Then in the VM the following functions are not really inline:
class VM {
void Cleanup ();
void Execute ()
{
try {
Run();
} catch (VMExitException& e) {
if (e.pstruct)
e.pstruct->SubRef(); // crash because pstruct ptr
is garbage
... // other cleanup
}
}
void Run ()
{
EStruct* thisreg = 0;
do {
int opcode = codeblock[cursor++];
switch (opcode) {
... lots of cases
case EAtom::EXIT: {
// logging here shows that thisreg is null
// but we try to create a VMExitException and
when caught
// by caller the member pstruct is garbage
throw VMExitException(thisreg);
}
}
};
}
};
Do you guys see my concern. Is it legal to create an exception struct
on a frame of the inner function and then catch it by reference in the
outer? If so, how is it possible that the frame of the inner is
preserved in the catch block of the outer, and if not, how do I
accomplish the transfer of information from the inner's state to the
outer via an exception. Note: in Java, its easy to do this because
exceptions live on the heap and are GC'ed.
Thanks,
Andy
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]