From c4fb4a11423f054f53186ed66a111eff2e70521d Mon Sep 17 00:00:00 2001
From: Campbell Barton <ideasman42@gmail.com>
Date: Mon, 4 Apr 2011 03:01:06 +0000
Subject: [PATCH] handle exceptions for reading non XML files - cant decode or
 parse, real errors in code will still raise exceptions.

---
 io_curve_svg/import_svg.py | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/io_curve_svg/import_svg.py b/io_curve_svg/import_svg.py
index d68c1113e..146f1e014 100644
--- a/io_curve_svg/import_svg.py
+++ b/io_curve_svg/import_svg.py
@@ -1814,6 +1814,15 @@ def load_svg(filepath):
 
 def load(operator, context, filepath=""):
 
-    load_svg(filepath)
+    # error in code should raise exceptions but loading
+    # non SVG files can give useful messages.
+    try:
+        load_svg(filepath)
+    except (xml.parsers.expat.ExpatError, UnicodeEncodeError) as e:
+        import traceback
+        traceback.print_exc()
+
+        operator.report({'WARNING'}, "Unable to parse XML, %s:%s for file %r" % (type(e).__name__, e, filepath))
+        return {'CANCELLED'}
 
     return {'FINISHED'}
-- 
GitLab