Raise Exception when load hanjatable failed.
authorHuang Peng <shawn.p.huang@gmail.com>
Fri, 15 Aug 2008 08:06:10 +0000 (16:06 +0800)
committerHuang Peng <shawn.p.huang@gmail.com>
Fri, 15 Aug 2008 08:06:10 +0000 (16:06 +0800)
engine/hangul.i

index 941d785..de7d861 100644 (file)
@@ -28,6 +28,7 @@
 
 %init %{
 %}
+
 %typemap (in) ucschar * {
     if (PyUnicode_Check ($input)) {
         $1 = PyUnicode_AsUnicode ($input);
     }
 }
 
+/* define exception */
+%exception {
+    $action
+    if (PyErr_Occurred ()) {
+        return NULL;
+    }
+}
+
 typedef int ucschar;
 
 /* define struct HangulKeyboard */
@@ -191,7 +200,13 @@ typedef struct {} HangulInputContext;
 typedef struct {} HanjaTable;
 %extend HanjaTable {
     HanjaTable (const char *name) {
-        return hanja_table_load (name);
+        HanjaTable *table = hanja_table_load (name);
+        if (table == NULL) {
+            PyErr_Format (PyExc_IOError,
+                            "Can not load HanjaTabel from %s.", name);
+            return NULL;
+        }
+        return table;
     }
 
     ~HanjaTable () {