changeset 17705:292319fb7fcc

Catch Magick++ errors and warnings when pinging image (bug #40267) * __magick_read__.cc: enclose call to ping() into a try/catch block
author Carnë Draug <carandraug@octave.org>
date Sun, 20 Oct 2013 17:57:17 +0100
parents 7903ae3b657d
children 97ed9dd479ab
files libinterp/dldfcn/__magick_read__.cc
diffstat 1 files changed, 19 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/dldfcn/__magick_read__.cc	Sun Oct 20 16:41:54 2013 +0100
+++ b/libinterp/dldfcn/__magick_read__.cc	Sun Oct 20 17:57:17 2013 +0100
@@ -652,8 +652,9 @@
     }
   catch (Magick::ErrorCoder& e)
     {
-      // FIXME: there's a WarningCoder and ErrorCoder. Shouldn't this
-      // exception cause an error?
+      // XXX: why is this error being caught as a warning? It has always
+      //      been like this (function was added the first time to the
+      //      Octave Forge image package with cset d756a7b6d533)
       warning ("Magick++ coder error: %s", e.what ());
     }
   catch (Magick::Exception& e)
@@ -1447,9 +1448,22 @@
     idx = 0;
 
   Magick::Image img;
-  img.subImage (idx);
-  img.subRange (1);
-  img.ping (filename);
+  img.subImage (idx); // start ping from this image (in case of multi-page)
+  img.subRange (1);   // ping only one of them
+  try
+    {
+      img.ping (filename);
+    }
+  catch (Magick::Warning& w)
+    {
+      warning ("Magick++ warning: %s", w.what ());
+    }
+  catch (Magick::Exception& e)
+    {
+      error ("Magick++ exception: %s", e.what ());
+      return retval;
+    }
+
   static const char *fields[] = {"rows", "columns", "format", 0};
   octave_scalar_map ping = octave_scalar_map (string_vector (fields));
   ping.setfield ("rows",    octave_value (img.rows ()));