Exception handling and Windows



Hi,

I have a problem with exception handling on Windows. In my application, I set up a global exception handler with the function Glib::add_exception_handler, so that this handler is supposed to be called when an exception is thrown during the execution of the main loop. It works fine when the program is built under Linux, but the exception handler set up by Glib::add_exception_handler is never called when the program is built under Windows.

I enclose a simple testcase. When clicking on the button:
- under Linux, the exception is normally catched in my_exception_handler,
- under Windows, the program terminates.

What's wrong? Thanks for your help.

Yoann

#include <gtkmm/main.h>
#include <gtkmm/window.h>
#include <gtkmm/button.h>
#include <exception>
#include <iostream>

class MyWindow : public Gtk::Window
{
	Gtk::Button my_button;

public:

	void on_button_clicked()
	{
		throw std::exception();
	}

	MyWindow() : Gtk::Window(), my_button("Do it!")
	{
		my_button.signal_clicked().connect(sigc::mem_fun(*this, &MyWindow::on_button_clicked));
		set_size_request(300, 200);
		add(my_button);
		show_all_children();
	}
};

void my_exception_handler()
{
	std::cerr << "Call to my_exception_handler" << std::endl;
	try {
		throw;
	}
	catch(std::exception &err) {
		std::cerr << "Exception catched. What: " << err.what() << std::endl;
	}
	catch(...) {
		std::cerr << "Something catched. Don't know what." << std::endl;
	}
}

int main(int argc, char *argv[])
{
	Gtk::Main kit(argc, argv);
	Glib::add_exception_handler(sigc::ptr_fun(&my_exception_handler));
	MyWindow window;
	Gtk::Main::run(window);
	return 0;
}


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]