1

In an small project i am using several boost packages (asio, property_tree, filesystem, etc.) and i had to notice, that everything works fine, until an exception gets thrown somewhere in the boost packages. It happens in all those packages, but i was now able to boil it down to the following minimal program:

#include <iostream>
#include "boost/throw_exception.hpp"

int main(int argc, char* argv[])
{
  boost::throw_exception(std::exception("foo")); // <-- this will produce the problem

  throw std::exception("foo"); // <-- this works as expected

  return 0;
}

The exception is thrown fine, but when the program terminates i get

Run-Time Check Failure #0 - The value of ESP was not properly 
saved across a function call ...

I tried to debug this (i am using boost 1.49.0 in visual studio 2010 express with crt statically linked) but the problem appears when all visible code is already executed. I can see that the std:exception destructor wen't through, but after that ("in" the return statement of my program) the message box is triggered.

EDIT: Some additional infos:

  • In the minimal program above, boost is only used headers only
  • No other lib-files are involved
  • Only ntdll.dll and kernel32.dll are loaded by the program
  • No additional threads are beeing created
  • The problem also appears, when i link dynamically against CRT

EDIT2: Again more infos:

  • added includes in the program above
  • the problem appears too, when i throw a runtime_error instead
  • the problem vanishes when i catch the exception with (...) or (std::exception)
  • the problem even remains cured, when i rethrow the exception

1 Answer 1

0

Can you try using the dynamic runtime, so that both Boost and your program use the same one? If you are linking statically to the runtime, then you might have two runtimes loaded into the process, which is can cause problems. The last time I saw that problem though, it was caused by having different calling conventions between a program and a DLL (e.g. cdecl/fastcall/pascal). Just using a static runtime shouldn't make a difference though.

BTW: There is a simple test that you can make to find out where the error is. If you include the according code from Boost into your program, you effectively get an in-place compiled, statically linked Boost. If that works, then you can be reasonably sure that the problem is the way that you build or link things.

7
  • "If you are linking statically to the runtime, then you might have two runtimes loaded into the process" - how comes? Does OP write he links Boost dynamically?
    – Igor R.
    Jul 12, 2013 at 5:21
  • Thanks for your reply, i added some statements to my question to clarify.
    – Janosch
    Jul 12, 2013 at 11:48
  • I tried now with dynamic CRT, the problem still exists. Any further Ideas?
    – Janosch
    Jul 12, 2013 at 15:06
  • Oh. I didn't even think of the possibility that you're using a header-only part of Boost, which of course rules out any linker-related issues. There are three more things that come to mind: 1. What if you actually catch the exception? 2. The standard doesn't have a ctor for std::exception taking a char*, that is an MS extension. What if you replace this with std::runtime_error instead? 3. Which #includes do you have? Jul 12, 2013 at 15:47
  • Tried your suggestions (thanks!) and added results in my question. By catching the exception, the problem is solved for me. Still the question remains open, since i cant explain what the problem actually is.
    – Janosch
    Jul 14, 2013 at 12:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.