From cf4a4b428569d2ee350e2951e16a52cb3fe6ef0a Mon Sep 17 00:00:00 2001 From: Richard Roberts Date: Wed, 22 Aug 2012 22:40:24 +0000 Subject: [PATCH] wrap turns exceptions into MATLAB errors --- wrap/Module.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/wrap/Module.cpp b/wrap/Module.cpp index b2f061838..681fb6925 100644 --- a/wrap/Module.cpp +++ b/wrap/Module.cpp @@ -481,12 +481,16 @@ void Module::matlab_code(const string& toolboxPath, const string& headerPath) co file.oss << " std::streambuf *outbuf = std::cout.rdbuf(&mout);\n\n"; file.oss << " _" << name << "_RTTIRegister();\n\n"; file.oss << " int id = unwrap(in[0]);\n\n"; - file.oss << " switch(id) {\n"; + file.oss << " try {\n"; + file.oss << " switch(id) {\n"; for(size_t id = 0; id < functionNames.size(); ++id) { - file.oss << " case " << id << ":\n"; - file.oss << " " << functionNames[id] << "(nargout, out, nargin-1, in+1);\n"; - file.oss << " break;\n"; + file.oss << " case " << id << ":\n"; + file.oss << " " << functionNames[id] << "(nargout, out, nargin-1, in+1);\n"; + file.oss << " break;\n"; } + file.oss << " }\n"; + file.oss << " } catch(const std::exception& e) {\n"; + file.oss << " mexErrMsgTxt((\"Exception from gtsam:\\n\" + std::string(e.what()) + \"\\n\").c_str());\n"; file.oss << " }\n"; file.oss << "\n"; file.oss << " std::cout.rdbuf(outbuf);\n"; // Restore cout