Skip to content
Snippets Groups Projects
Verified Commit 0c68e733 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
parent 25231f66
Branches
No related tags found
No related merge requests found
/* /*
* Copyright © 2019 Dynare Team * Copyright © 2019-2022 Dynare Team
* *
* This file is part of Dynare. * This file is part of Dynare.
* *
...@@ -139,7 +139,10 @@ DynamicModelMatlabCaller::eval(int it, double *resid) ...@@ -139,7 +139,10 @@ DynamicModelMatlabCaller::eval(int it, double *resid)
mxArray *exception = mexCallMATLABWithTrap(1, plhs, 6, prhs, funcname.c_str()); mxArray *exception = mexCallMATLABWithTrap(1, plhs, 6, prhs, funcname.c_str());
if (exception) 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); mxDestroyArray(T_mx);
T_mx = plhs[0]; T_mx = plhs[0];
...@@ -152,7 +155,10 @@ DynamicModelMatlabCaller::eval(int it, double *resid) ...@@ -152,7 +155,10 @@ DynamicModelMatlabCaller::eval(int it, double *resid)
mxArray *exception = mexCallMATLABWithTrap(1, plhs, 7, prhs, funcname.c_str()); mxArray *exception = mexCallMATLABWithTrap(1, plhs, 7, prhs, funcname.c_str());
if (exception) 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])) if (mxIsComplex(plhs[0]))
plhs[0] = cmplxToReal(plhs[0]); plhs[0] = cmplxToReal(plhs[0]);
...@@ -169,7 +175,10 @@ DynamicModelMatlabCaller::eval(int it, double *resid) ...@@ -169,7 +175,10 @@ DynamicModelMatlabCaller::eval(int it, double *resid)
mxArray *exception = mexCallMATLABWithTrap(1, plhs, 7, prhs, funcname.c_str()); mxArray *exception = mexCallMATLABWithTrap(1, plhs, 7, prhs, funcname.c_str());
if (exception) 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) if (jacobian_mx)
{ {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment