Take the 2-minute tour ×

this is the error I'm receiving:

enter image description here

I would like to know this:

  1. how do set up try catch block to handle that error? OR
  2. how do handle that error before it hapens if try catch is not possible?

I'm receiving this error when I call a member function trough pointer to member function with wrong signature. That error of course won't happen if I call it with correct signature , but, I just wanna know how do I handle it if it happens.

share|improve this question
Fix your code, don't try to 'handle' a rather fatal mishap. Having the stack pointer imbalanced causes lots of random misery, about as bad as a corrupted heap. –  Hans Passant Jan 15 '12 at 19:57
Thanks Hans, I don't have to fix my code cos it has no such errors unles I do it manualy. I just wanna know if it's possible to handle that. EDIT and if it is recommended to handle such erros. –  codekiddy Jan 15 '12 at 20:01
@HansPassant: I disagree about the "about as bad as a corrupted heap": It's worse than a corrupted heap. With a corrupted stack you cannot even safely return from your function. –  celtschk Jan 15 '12 at 20:13
OK, so the answer is: do NOT handle and fix your code. thanks I think I got your point. –  codekiddy Jan 15 '12 at 20:17
@celtschk - If only that was true, code that fails immediately is much easier to troubleshoot. The typical function prologue restores the stack pointer. This tends to blow up when the optimizer is turned to eleven. –  Hans Passant Jan 15 '12 at 20:19
show 3 more comments

3 Answers

up vote 2 down vote accepted

1. You can't handle that error with try/catch.

This is because try/catch relies on the call stack and your error is that your call stack is corrupted.

2. There is no reasonable runtime method to know in advance that code is going to corrupt the stack.

These problems are typically handled by using caution when casting (function) pointers in the code itself. The compiler will not allow an incorrect function pointer assignment unless you're forcing it with a cast.

share|improve this answer
so only handling method is using caution when casting. thanks for that explanation. –  codekiddy Jan 15 '12 at 20:29
add comment

Under windows you should be able to catch this with SEH __try / __except block. Equivalent for linux are signals. If you know that code that executes in try/catch can produce such error, then use it for logging what function caused it or informing user of error. I doubt you can recover from such situation. Maybe if call is made on separate thread? or process?

share|improve this answer
I may be wrong, but IIRC this thing doesn't pop up from a SEH exception, but directly from an assertion in the CRT code (in particular in the stack bounds checking code). –  Matteo Italia Jan 15 '12 at 20:18
You are right, I thought this will work, there are some entries on SO about SEH and stack corruption - and that it wont work. –  marcin_j Jan 15 '12 at 20:35
add comment

You cannot catch a function call with the wrong calling convention, because it is not an exception in C++ terms. The error is a potentially fatal one which has to do with the structure or formulation of the program, and you should not attempt to "handle" it unless you are doing some serious low-level backward compatibility stunts a la Raymond Chen.

share|improve this answer
add comment

Your Answer


