codekiddy
codekiddy

Reputation: 6137

How to handle Run time check failure in C++?

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.

Upvotes: 1

Views: 805

Answers (2)

Drew Dormann
Drew Dormann

Reputation: 63735

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.

Upvotes: 2

John Zwinck
John Zwinck

Reputation: 249123

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.

Upvotes: 0

Related Questions