From 5b1c7b73d0cb2dbbf944c3be670a7f2d74547e0f Mon Sep 17 00:00:00 2001
From: Josh Blum <josh@joshknows.com>
Date: Mon, 26 Sep 2011 21:22:13 -0700
Subject: swig: language independent exception handler

---
 gruel/src/swig/pmt_swig.i | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

(limited to 'gruel/src/swig/pmt_swig.i')

diff --git a/gruel/src/swig/pmt_swig.i b/gruel/src/swig/pmt_swig.i
index 3b0eb45c88..34c7d4b7cf 100644
--- a/gruel/src/swig/pmt_swig.i
+++ b/gruel/src/swig/pmt_swig.i
@@ -36,6 +36,24 @@
 using namespace pmt;
 %}
 
+////////////////////////////////////////////////////////////////////////
+// Language independent exception handler
+////////////////////////////////////////////////////////////////////////
+%include exception.i
+
+%exception {
+    try {
+        $action
+    }
+    catch(std::exception &e) {
+        SWIG_exception(SWIG_RuntimeError, e.what());
+    }
+    catch(...) {
+        SWIG_exception(SWIG_RuntimeError, "Unknown exception");
+    }
+
+}
+
 // Template intrusive_ptr for Swig to avoid dereferencing issues
 class pmt_base;
 //%import <intrusive_ptr.i>
-- 
cgit v1.2.3