Commit 0c726a3f authored by hbristow's avatar hbristow

Improved exception handling and unit tests

parent bbece095
...@@ -27,6 +27,16 @@ std::vector<Bridge> {{function.name}}({{clss.name}}& inst, const std::vector<Bri ...@@ -27,6 +27,16 @@ std::vector<Bridge> {{function.name}}({{clss.name}}& inst, const std::vector<Bri
// setup // setup
// invoke // invoke
try {
// invoke
} catch(cv::Exception& e) {
mexErrMsgTxt(std::string("cv::exception caught: ").append(e.what()).c_str());
} catch(std::exception& e) {
mexErrMsgTxt(std::string("std::exception caught: ").append(e.what()).c_str());
} catch(...) {
mexErrMsgTxt("Uncaught exception occurred in {{fun.name}}");
}
// setdown // setdown
} }
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include "bridge.hpp" #include "bridge.hpp"
#include <string> #include <string>
#include <vector> #include <vector>
#include <exception>
#include <opencv2/core.hpp> #include <opencv2/core.hpp>
{% block includes %} {% block includes %}
{% endblock %} {% endblock %}
...@@ -42,7 +43,9 @@ void mexFunction(int nlhs, mxArray* plhs[], ...@@ -42,7 +43,9 @@ void mexFunction(int nlhs, mxArray* plhs[],
try { try {
{{fun.name}}(); {{fun.name}}();
} catch(cv::Exception& e) { } catch(cv::Exception& e) {
mexErrMsgTxt(std::string("OpenCV exception caught: ").append(e.what()).c_str()); mexErrMsgTxt(std::string("cv::exception caught: ").append(e.what()).c_str());
} catch(std::exception& e) {
mexErrMsgTxt(std::string("std::exception caught: ").append(e.what()).c_str());
} catch(...) { } catch(...) {
mexErrMsgTxt("Uncaught exception occurred in {{fun.name}}"); mexErrMsgTxt("Uncaught exception occurred in {{fun.name}}");
} }
......
...@@ -5,7 +5,7 @@ classdef OpenCVTest < matlab.unittest.TestCase ...@@ -5,7 +5,7 @@ classdef OpenCVTest < matlab.unittest.TestCase
methods(Test) methods(Test)
% check if the autogenerated functions can be found % check if the autogenerated functions can be found
function randExists(testcase) function functionsExist(testcase)
try try
cv.rand(); cv.rand();
catch catch
...@@ -13,5 +13,33 @@ classdef OpenCVTest < matlab.unittest.TestCase ...@@ -13,5 +13,33 @@ classdef OpenCVTest < matlab.unittest.TestCase
end end
testcase.verifyTrue(true); testcase.verifyTrue(true);
end end
% check that std exception is thrown
function stdException(testcase)
try
std_exception();
testcase.verifyFail();
catch
% TODO: Catch more specific exception
testcase.verifyTrue(true);
end
end
% check that OpenCV exceptions are correctly caught
function cvException(testcase)
testcase.verifyFail();
end
% check that all exceptions are caught
function allException(testcase)
try
exception();
testcase.verifyFail();
catch
% TODO: Catch more specific exception
testcase.verifyTrue(true);
end
end
end end
end end
...@@ -3,3 +3,6 @@ opencv_tests = OpenCVTest(); ...@@ -3,3 +3,6 @@ opencv_tests = OpenCVTest();
%run the tests %run the tests
result = run(opencv_tests); result = run(opencv_tests);
% shutdown
exit();
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment