Skip to content
Snippets Groups Projects
Verified Commit 31e4b6da authored by Sébastien Villemot's avatar Sébastien Villemot
Browse files

perfect_foresight_problem MEX: error out properly when called MATLAB function triggers an exception

Closes: #1832
(cherry picked from commit 0c68e733)
parent d4e6c5dc
Branches
Tags
No related merge requests found
/*
* Copyright © 2019 Dynare Team
* Copyright © 2019-2022 Dynare Team
*
* This file is part of Dynare.
*
......@@ -139,7 +139,10 @@ DynamicModelMatlabCaller::eval(int it, double *resid)
mxArray *exception = mexCallMATLABWithTrap(1, plhs, 6, prhs, funcname.c_str());
if (exception)
error_msg = std::string{"An error occurred when calling "} + funcname;
{
error_msg = std::string{"An error occurred when calling "} + funcname;
return; // Avoid manipulating null pointers in plhs, see #1832
}
mxDestroyArray(T_mx);
T_mx = plhs[0];
......@@ -152,7 +155,10 @@ DynamicModelMatlabCaller::eval(int it, double *resid)
mxArray *exception = mexCallMATLABWithTrap(1, plhs, 7, prhs, funcname.c_str());
if (exception)
error_msg = std::string{"An error occurred when calling "} + funcname;
{
error_msg = std::string{"An error occurred when calling "} + funcname;
return; // Avoid manipulating null pointers in plhs, see #1832
}
if (mxIsComplex(plhs[0]))
plhs[0] = cmplxToReal(plhs[0]);
......@@ -169,7 +175,10 @@ DynamicModelMatlabCaller::eval(int it, double *resid)
mxArray *exception = mexCallMATLABWithTrap(1, plhs, 7, prhs, funcname.c_str());
if (exception)
error_msg = std::string{"An error occurred when calling "} + funcname;
{
error_msg = std::string{"An error occurred when calling "} + funcname;
return; // Avoid manipulating null pointers in plhs, see #1832
}
if (jacobian_mx)
{
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment