[gtkmm] Icon theme demo: Catch exceptions while loading icons



commit 3bd6e0ed5d844bed2ea012eee113e61be2db417d
Author: Kjell Ahlstedt <kjell ahlstedt bredband net>
Date:   Thu Mar 5 18:25:30 2015 +0100

    Icon theme demo: Catch exceptions while loading icons
    
    * demos/gtk-demo/example_icontheme.cc: Catch exceptions from the call to
    Gtk::IconInfo::load_icon(). It throws a Gdk::PixbufError if an icon file is
    corrupt.

 demos/gtk-demo/example_icontheme.cc |   24 +++++++++++++++++++-----
 1 files changed, 19 insertions(+), 5 deletions(-)
---
diff --git a/demos/gtk-demo/example_icontheme.cc b/demos/gtk-demo/example_icontheme.cc
index cd3c190..a2df468 100644
--- a/demos/gtk-demo/example_icontheme.cc
+++ b/demos/gtk-demo/example_icontheme.cc
@@ -17,6 +17,7 @@
 #include <map>
 #include <algorithm>
 #include <sstream>
+#include <iostream>
 
 class Example_IconTheme: public Gtk::Window
 {
@@ -101,7 +102,7 @@ Example_IconTheme::Example_IconTheme()
   // add columns to the TreeView, mapping model m_columns to TreeView Columns:
 
   //The pixbuf/iconname column:
-  Gtk::TreeView::Column* pColumn = Gtk::manage(new Gtk::TreeView::Column("Icon Name"));
+  Gtk::TreeView::Column* pColumn = Gtk::manage(new Gtk::TreeView::Column("Icon Pixbuf and Icon Name"));
 
   //We specify the renderer(s) after construction.
   // The pixbuf/iconname column uses two CellRenderers: Here we see why Gtk::TreeView is so good.
@@ -183,10 +184,23 @@ Glib::RefPtr<Gtk::TreeModel> Example_IconTheme::create_model()
     // Populate icon column.
     if (icon_info)
     {
-      if (icon_info.get_filename().empty())
-        row[m_columns.icon] = icon_info.get_builtin_pixbuf();
-      else
-        row[m_columns.icon] = icon_info.load_icon();
+      try
+      {
+        if (icon_info.get_filename().empty())
+          row[m_columns.icon] = icon_info.get_builtin_pixbuf();
+        else
+          row[m_columns.icon] = icon_info.load_icon();
+      }
+      catch (const Gdk::PixbufError& err)
+      {
+        std::cout << "Gdk::PixbufError when loading the \"" << *iconiter
+          << "\" icon: " << err.what() << std::endl;
+      }
+      catch (const Glib::Error& err)
+      {
+        std::cout << "Glib::Error when loading the \"" << *iconiter
+          << "\" icon: " << err.what() << std::endl;
+      }
     }
 
     // Populate icon name column.


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