Callstack of a std::exception does not include the location of the throw

We have an C++ app which runs on multiple platforms and is build using the Qt framework. For a while we had issues with unexplainable stack traces reported by testflight users.

Now I found out that if I just put throw std::runtime_error("something"); at the start of my main method the resulting crash call stack would not point to my main method.

Is there something I can do (compiler flags/variables/code etc) to have the call stack from the actual throw show up in XCode and testflight?

Replies

I think that in this case you must have a global QAppleLogActuvity object, and its destructor is being run when your exception leaves main().

If that didn’t exist, you might get a stack trace for an unhandled exception at the point of the throw.

I have a vague recollection that you may be able to disable running destructors for global objects at program termination with a build setting. That may or may not help.

I’ve never got this to work in a useful way. What is your policy on use of exceptions? I suggest not using them unless you are actually going to catch them. For unrecoverable fatal errors that “shouldn’t happen”, use assert().

Are you specifically concerned about the backtraces in a crash report? If so, Apple’s crash reporter has a long-standing incompatibility with C++ exceptions thrown from within a run loop. See this post.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Yes, I would like to find out why my app crashed, Its likely due to a c++ exception that's incorrectly handled by my code. But there is no way of fixing it until I know where it has been thrown. All suggestions are welcome as this has become a serious issue for us. We are using the Qt framework and except from complaining users the only thing we get is the crashes in test flight (with a call stack that is not providing insight).

Is there any way of disabling the catch all in the run loop?

Is there any way of getting the exception .what() information in the test flight log?