diff --git a/src/gui_builder.cc b/src/gui_builder.cc index 0e904e6..428891c 100644 --- a/src/gui_builder.cc +++ b/src/gui_builder.cc @@ -28,6 +28,11 @@ #include "gui_builder.hh" #include "graphical_preferences_editor.hh" +#include "backend/cpu_policy_exception.hh" +#include "backend/malformed_policy_exception.hh" +#include "backend/null_policy_exception.hh" +#include "backend/user_interrupt_exception.hh" + #include "backend/cpu_policies_gatekeeper.hh" #include "backend/cpu_policy.hh" #include "backend/cpu_policy_manager.hh" @@ -38,6 +43,7 @@ #include "backend/serializer.hh" #include +#include #include #include #include @@ -329,7 +335,9 @@ SimulationController::on_simulation_run() _toolbt_stop->set_sensitive(true); _break_requested = false; - _sim.run(); + // Used instead of simply calling "_sim.run()" to + // have exception handling only in one place: + run_simulation_adaptor(); } @@ -405,7 +413,55 @@ SimulationController::update(const Simulation& simulation) bool SimulationController::run_simulation_adaptor() { + using Gtk::MessageDialog; + using namespace Glib; + if(!_break_requested) - _sim.run(); + try + { + _sim.run(); + } + catch(const UserInterruptException& uie) + { + // Show the user a dialog + MessageDialog diag(_("The selected user CPU policy stopped before returning:\n") + Markup::escape_text(uie.what()), + true, Gtk::MESSAGE_ERROR, Gtk::BUTTONS_OK, true); + diag.run(); + } + catch(const MalformedPolicyException& mpe) + { + // Show user a dialog + MessageDialog diag(_("The selected user CPU policy was malformed and didn't run:\n") + Markup::escape_text(mpe.what()), + true, Gtk::MESSAGE_ERROR, Gtk::BUTTONS_OK, true); + diag.run(); + + try + { + // Deactivate the policy + _sim.set_policy(NULL); + } + catch(const CPUPolicyException& cpe) + { + // Fatal error. We should never get here. + std::cerr << _(" [EE] Fatal error. Impossible to deactivate the policy in ") << __FILE__ << ":" << __LINE__ + << std::endl << _(" [EE] ") << cpe.what() << std::endl; + ; + abort(); + } + } + catch(const NullPolicyException& npe) + { + MessageDialog diag(_("No active policy selected:\n") + Markup::escape_text(npe.what()), + true, Gtk::MESSAGE_ERROR, Gtk::BUTTONS_OK, true); + diag.run(); + + } + catch(const CPUPolicyException& cpe) + { + MessageDialog diag(_("Unexpected error:\n") + Markup::escape_text(cpe.what()), + true, Gtk::MESSAGE_ERROR, Gtk::BUTTONS_OK, true); + diag.run(); + } + return false; }