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

Closes: #1832
mr#1991
Sébastien Villemot 2022-01-03 17:20:07 +01:00
parent 25231f6634
commit 0c68e7336b
No known key found for this signature in database
GPG Key ID: 2CECE9350ECEBE4A
1 changed files with 13 additions and 4 deletions

View File

@ -1,5 +1,5 @@
/*
* 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)
{