1

I'm not sure how to approach it. The question was given after a lecture about Exceptions so I assume it has something to do with it.

Anindya Dutta
  • 1,972
  • 2
  • 18
  • 33
KitKat
  • 131
  • 1
  • 1
  • 4
  • Obvious possibilities would be things like losing power at the wrong time, or simply terminating the entire process (e.g., a `kill -9` under Linux or `TerminateProcess` under Windows). – Jerry Coffin Jun 04 '15 at 15:51
  • uhhh, something like exit(1)? – KitKat Jun 04 '15 at 15:56
  • calling `longjmp()` would prevent proper stack unwinding but would still move the stack pointer and program counter to some earlier location (which is why it's often considered a problematic call). – mah Jun 04 '15 at 15:57
  • I think if you throw an exception during the stack unwinding process it will just abort, idk if that counts as "preventing" though. – Borgleader Jun 04 '15 at 15:58

2 Answers2

1

Default signal handlers, or calls to abort() and exit() could prevent stack unvinding.

And there's many more situations, like pointed out in mah's comment.

Especially any mechanism bypassing the c++ exception model will do so. Even threads have a model to do proper stack unwinding, with having them propagated to their parents (if they weren't detached).

Community
  • 1
  • 1
πάντα ῥεῖ
  • 1
  • 13
  • 116
  • 190
1

When a scope is exited, stack unwinding starts, which means the compiler inserts calls to destructors of automatic variables, as explained in this answer.

For this process to be prevented, you would need a sudden exiting of the process, which could be loss of power, force quitting the process through the command line, etc.

Community
  • 1
  • 1
Olivier Poulin
  • 1,778
  • 8
  • 15