Exceptions not caught by catch(...)
Exceptions not caught by catch(...)
- Subject: Exceptions not caught by catch(...)
- From: "Michael Williamson" <email@hidden>
- Date: Tue, 23 Dec 2008 13:06:00 +1100
Short Summary: exceptions are failing to be caught in main, and this includes with a catch(...). After some testing, it looks like the problem only occurs when I'm going through some Carbon event handlers (SendEventToEventTarget and related).
If I trigger the same exception when bypassing this, the exceptions are caught correctly in main.
I've seen reference to the gcc visibility issue with exceptions, but I would have thought catch(...) should avoid that. Plus I've compiled all of this with gcc 4.2 (via XCode 3.1) which I believe has solved that issue?
Any ideas what could cause this?
On with the details. Sorry for the length...
***The problem case (exceptions not caught in main) ***
This is the callstack just before the exception (a type derived from std::exception) is thrown:
=====
#0 0x00003ed0 in CompositorDemo_FrameListener::handleMouseButtonDown at CompositorDemo_FrameListener.cpp:708
#1 0x0000f270 in CEGUI::MemberFunctionSlot<CompositorDemo_FrameListener>::operator() at CEGUIMemberFunctionSlot.h:55
#2 0x0048cb78 in CEGUI::SubscriberSlot::operator() at CEGUISubscriberSlot.h:82
#3 0x0048c470 in CEGUI::Event::operator() at CEGUIEvent.cpp:101
#4 0x0048f350 in CEGUI::EventSet::fireEvent_impl at CEGUIEventSet.cpp:228
#5 0x0048f3cc in CEGUI::EventSet::fireEvent at CEGUIEventSet.cpp:170
#6 0x004e393c in CEGUI::Window::onMouseButtonDown at CEGUIWindow.cpp:2978
#7 0x004d5aa0 in CEGUI::System::injectMouseButtonDown at CEGUISystem.cpp:791
#8 0x000054fc in CompositorDemo_FrameListener::mousePressed at CompositorDemo_FrameListener.cpp:541
#9 0x0008c344 in OIS::MacMouse::_mouseCallback at MacMouse.cpp:265
#10 0x00083328 in MouseWrapper at MacHelpers.cpp:154
#11 0x9601ce2c in DispatchEventToHandlers
#12 0x9601bfc4 in SendEventToEventTargetInternal
#13 0x96038f28 in SendEventToEventTarget
#14 0x9604c0cc in ToolboxEventDispatcherHandler
#15 0x9601d280 in DispatchEventToHandlers
#16 0x9601bfc4 in SendEventToEventTargetInternal
#17 0x96038f28 in SendEventToEventTarget
#18 0x0179956c in Ogre::WindowEventUtilities::messagePump at OgreWindowEventUtilities.cpp:101
#19 0x0166fb1c in Ogre::Root::startRendering at OgreRoot.cpp:827
#20 0x00017fa4 in CompositorDemo::go at Compositor.cpp:85
#21 0x00018008 in main at Compositor.cpp:613
=====
I have try/catch/rethrow for std::exception and all exceptions (...) in these key places:
#10 MouseWrapper (an OIS function)
#18 Ogre::WindowEventUtilities::messagePump
#21 main
At each catch I'm logging to see if it's hit.
The console shows that the exception is caught fine at #10 (MouseWrapper), but it is not caught at all in #18 (messagePump). That's immediately after passing through the Carbon calls (#11 to #17).
Nor is it caught in main (#21). Instead I get this in the console:
"terminate called after throwing an instance of 'std::exception'"
***The working case (exception caught in main)***
If I bypass the Carbon calls, then exceptions are all caught fine, including in main.
Admittedly this also bypasses the OIS functions, but it was correctly caught in MouseWrapper in the previous test (the "last" OIS function).
Here's the callstack before first throw for the working case:
=====
#0 0x00003c14 in CompositorDemo_FrameListener::handleMouseButtonDown at CompositorDemo_FrameListener.cpp:708
#1 0x0000f150 in CEGUI::MemberFunctionSlot<CompositorDemo_FrameListener>::operator() at CEGUIMemberFunctionSlot.h:55
#2 0x0048cb78 in CEGUI::SubscriberSlot::operator() at CEGUISubscriberSlot.h:82
#3 0x0048c470 in CEGUI::Event::operator() at CEGUIEvent.cpp:101
#4 0x0048f350 in CEGUI::EventSet::fireEvent_impl at CEGUIEventSet.cpp:228
#5 0x0048f3cc in CEGUI::EventSet::fireEvent at CEGUIEventSet.cpp:170
#6 0x004e393c in CEGUI::Window::onMouseButtonDown at CEGUIWindow.cpp:2978
#7 0x004d5aa0 in CEGUI::System::injectMouseButtonDown at CEGUISystem.cpp:791
#8 0x00005a6c in CompositorDemo_FrameListener::frameRenderingQueued at CompositorDemo_FrameListener.cpp:432
#9 0x0166f578 in Ogre::Root::_fireFrameRenderingQueued at OgreRoot.cpp:704
#10 0x0166f680 in Ogre::Root::_fireFrameRenderingQueued at OgreRoot.cpp:761
#11 0x0166f700 in Ogre::Root::_updateAllRenderTargets at OgreRoot.cpp:1150
#12 0x0166fa1c in Ogre::Root::renderOneFrame at OgreRoot.cpp:855
#13 0x0166fb24 in Ogre::Root::startRendering at OgreRoot.cpp:829
#14 0x00017e84 in CompositorDemo::go at Compositor.cpp:85
#15 0x00017ee8 in main at Compositor.cpp:613
=====
For completeness, here's the try block of main. I don't change this file nor the #defines across the above tests, so the conditional compilation should be identical.
=====
try {
app.go();
} catch( Ogre::Exception& e ) {
#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
MessageBox( NULL, e.getFullDescription().c_str(), "An exception has occured!", MB_OK | MB_ICONERROR | MB_TASKMODAL);
#else
std::cerr << "An Ogre exception has occured: " << e.getFullDescription();
#endif
}
catch( OIS::Exception& e )
{
std::cerr << "An OIS exception has occured: " << e.what();
}
catch( std::exception& e )
{
std::cerr << "A std exception has occured: " << e.what();
}
catch( ... )
{
std::cerr << "An unknown exception has occured";
}
====
Other details:
These are Carbon apps / frameworks.
XCode 3.1 (using gcc 4.2, compiled against OSX 10.5 SDK)
PowerPC with OSX 10.5.5
If you got this far, thanks for your patience!
- Michael
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden