Skip to content

Commit 33d345a

Browse files
author
Dominic Price
committed
Catch Action* exceptions and present message box
1 parent 547d2ef commit 33d345a

File tree

5 files changed

+22
-2
lines changed

5 files changed

+22
-2
lines changed

client_server/Actions.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "DocumentThread.hh"
66
#include "GUIBase.hh"
77

8+
#include <boost/core/demangle.hpp>
89
#include <iostream>
910

1011
using namespace cadabra;
@@ -29,7 +30,8 @@ void ActionBase::execute(DocumentThread& cl, GUIBase& )
2930
}
3031
++it;
3132
}
32-
throw std::logic_error("ActionAddCell: cannot find cell with id "+std::to_string(ref_id.id));
33+
std::string class_name = boost::core::demangle(typeid(*this).name());
34+
throw std::logic_error(class_name + ": cannot find cell with id "+std::to_string(ref_id.id));
3335
}
3436

3537
ActionAddCell::ActionAddCell(DataCell cell, DataCell::id_t ref_id, Position pos_)

client_server/DocumentThread.cc

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,12 @@ void DocumentThread::process_action_queue()
187187
// Execute the action; this will run synchronously, so after
188188
// this returns the doc and visual representation have both been
189189
// updated.
190-
ab->execute(*this, *gui);
190+
try {
191+
ab->execute(*this, *gui);
192+
}
193+
catch (const std::exception& err) {
194+
on_unhandled_error(err);
195+
}
191196
// Lock the queue to remove the action just executed, and
192197
// add it to the undo stack.
193198
stack_mutex.lock();
@@ -198,6 +203,10 @@ void DocumentThread::process_action_queue()
198203
stack_mutex.unlock();
199204
}
200205

206+
bool DocumentThread::on_unhandled_error(const std::exception& err)
207+
{
208+
return true;
209+
}
201210

202211
DocumentThread::Prefs::Prefs(bool use_defaults)
203212
{

client_server/DocumentThread.hh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ namespace cadabra {
151151
/// while this is running. So a running action can add more actions.
152152

153153
void process_action_queue();
154+
virtual bool on_unhandled_error(const std::exception& err);
154155

155156

156157

frontend/gtkmm/NotebookWindow.cc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -591,6 +591,13 @@ bool NotebookWindow::on_configure_event(GdkEventConfigure *cfg)
591591
return ret;
592592
}
593593

594+
bool NotebookWindow::on_unhandled_error(const std::exception& err)
595+
{
596+
Gtk::MessageDialog md(*this, err.what(), false, Gtk::MessageType::MESSAGE_ERROR, Gtk::ButtonsType::BUTTONS_OK, true);
597+
md.run();
598+
return true;
599+
}
600+
594601
void NotebookWindow::set_title_prefix(const std::string& pf)
595602
{
596603
title_prefix=pf;

frontend/gtkmm/NotebookWindow.hh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ namespace cadabra {
115115
virtual bool on_key_press_event(GdkEventKey*) override;
116116
virtual bool on_delete_event(GdkEventAny*) override;
117117
virtual bool on_configure_event(GdkEventConfigure *cfg) override;
118+
virtual bool on_unhandled_error(const std::exception& err) override;
118119

119120
DTree::iterator current_cell;
120121

0 commit comments

Comments
 (0)