diff --git a/ag-common/functions/pythonfunction.hh b/ag-common/functions/pythonfunction.hh
index 0f0452f0b8339726bb5740af17f724beda67ad3a..ade6e246d2ce24e2ff727f85679760d89e0241cc 100644
--- a/ag-common/functions/pythonfunction.hh
+++ b/ag-common/functions/pythonfunction.hh
@@ -98,6 +98,14 @@ struct EmbeddedPython
         PyObject* pModule = PyImport_Import(pModuleName);
         PyObject* pMember = PyObject_GetAttrString(pModule, memberName.c_str());
 
+        if (!pModuleName)
+            DUNE_THROW(Dune::Exception, "failed to construct python string for " << moduleName);
+        if (!pModule)
+            DUNE_THROW(Dune::Exception, "failed to retrieve python module " << moduleName);
+        if (!pMember)
+            DUNE_THROW(Dune::Exception, "failed to retrieve python member " << memberName
+                << " from module " << moduleName);
+        
         // decrement reference counts
         Py_DECREF(pModuleName);
         Py_DECREF(pModule);
@@ -111,6 +119,13 @@ struct EmbeddedPython
         PyObject* pClassArgs = PyTuple_New(0);
         PyObject* pObject = PyObject_CallObject(pClass, pClassArgs);
 
+        if (!pClass)
+            DUNE_THROW(Dune::Exception, "failed to retrieve python class " << className);
+        if (!pClassArgs)
+            DUNE_THROW(Dune::Exception, "failed to create python class arguments");
+        if (!pObject)
+            DUNE_THROW(Dune::Exception, "failed to create python class object for class " << className);
+        
         // decrement reference counts
         Py_DECREF(pClass);
         Py_DECREF(pClassArgs);
@@ -222,7 +237,9 @@ class PythonFunction :
             PyRun_SimpleString(s.str().c_str());
 
             // get reference for python function
-            setCallable(EmbeddedPython::getModuleMember("__main__", name), true);
+            PyObject* fnkt = EmbeddedPython::getModuleMember("__main__", name);
+            assert(fnkt != 0);
+            setCallable(fnkt, true);
         }
 
         virtual ~PythonFunction()