Main Content
Error Handling in C MEX Files
The mexErrMsgIdAndTxt
function in the
C
Matrix API prints error information and terminates your MEX function. The
mexWarnMsgIdAndTxt
function prints
information, but does not terminate the MEX function.
char *buf; int buflen; if (mxIsChar(prhs[0])) { if (mxGetString(prhs[0], buf, buflen) == 0) { mexPrintf("The input string is: %s\n", buf); } else { mexErrMsgIdAndTxt("MyProg:ConvertString", "Could not convert string data."); // exit MEX file } } else { mexWarnMsgIdAndTxt("MyProg:InputString", "Input should be a string to print properly."); } // continue with processing
For information about error handling in C++ MEX functions written with the MATLAB Data API for C++, see Handle Inputs and Outputs.