1

Suddenly my code started to throws an exception First-chance exception at 0x7731c41f in VideoPlayer.exe: Microsoft C++ exception: GenICam::RuntimeException at memory location 0x0018f5dc.. I could not find where exactly it throws from, so I commented all in main function and everything outside the main. I started to uncomment blocks of code one by one whilst the code in main remains commented. While doing it I noticed that there is function A that when it is commented there is no exception, but when it's uncommented it throws the exception above.

I don't understand how it can cause exeception if it's not called ( I placed breakpoint in it and code in main is commented)?

Mats Petersson
  • 126,704
  • 14
  • 140
  • 227
theateist
  • 13,879
  • 17
  • 69
  • 109

2 Answers2

2

You function will be used during the static initialization. Take the following example:

#include <iostream>
bool static_func()
{
    std::cout << "Before main" << std::endl;
    return true;
}
static const bool b = static_func();
int main()
{
    std::cout << "We are main" << std::endl;
    return 0;
}

Since you only see a first chance exception it will be caught and handled. I have seen such constructs in abstract factories for example, where the factory configures itself.
The reason why your breakpoint is not hit must be something else.

mkaes
  • 13,781
  • 10
  • 52
  • 72
  • I checked the code in `A` function and there is use of 3rd-party type (`BCamera camera;`). Probably when `A` is commented linker exclude it from final code and when `A` is uncommented linker include that type and because of that probably somewhere there are some global/static objects instantiation. Is there any way to debug such thing? – theateist Jun 02 '13 at 15:19
0

In VS, Debug menu, Exceptions... check the throw column for the matching type. Then start debugging and it will stop exactly where throw happens. And you can look around why.

Balog Pal
  • 16,195
  • 2
  • 23
  • 37