[gtkmm/gtkmm-3-18] treeview_editable_cells demo: Catch exception from std::stoi
- From: Murray Cumming <murrayc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtkmm/gtkmm-3-18] treeview_editable_cells demo: Catch exception from std::stoi
- Date: Thu, 14 Apr 2016 16:07:17 +0000 (UTC)
commit b3eb1aa850c4bfc6838351d7c74f5c330ec264e0
Author: Kjell Ahlstedt <kjell ahlstedt bredband net>
Date: Thu Feb 25 16:06:31 2016 +0100
treeview_editable_cells demo: Catch exception from std::stoi
demos/gtk-demo/example_treeview_editable_cells.cc | 12 +++++++++++-
1 files changed, 11 insertions(+), 1 deletions(-)
---
diff --git a/demos/gtk-demo/example_treeview_editable_cells.cc
b/demos/gtk-demo/example_treeview_editable_cells.cc
index 4bf72de..34955ee 100644
--- a/demos/gtk-demo/example_treeview_editable_cells.cc
+++ b/demos/gtk-demo/example_treeview_editable_cells.cc
@@ -7,6 +7,7 @@
*/
#include <cstdlib>
+#include <iostream>
#include <gtkmm.h>
class CellItem_Product
@@ -202,7 +203,16 @@ void Example_TreeView_EditableCells::on_column_number_edited(const Glib::ustring
if(iter)
{
//Convert the text to a number, using the same logic used by GtkCellRendererText when it stores
numbers.
- auto new_value = std::stoi(new_text);
+ int new_value = 0;
+ try
+ {
+ new_value = std::stoi(new_text);
+ }
+ catch (const std::exception& err)
+ {
+ std::cout << "Could not convert \"" << new_text << "\" to an integer. ("
+ << err.what() << ")" << std::endl;
+ }
//Store the user's new text in the model:
Gtk::TreeRow row = *iter;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]