User`s guide
3 Writing S-Functions As C-MEX files
3-14
your S-function generates an exception when this option is set, unpredictable
results will occur.
All
mex* routines have the potential of long jumping. In addition several mx*
routines have the potential of long jumping. To avoid any difficulties, use only
the API routines that retrieve a pointer or determine the size of param eters.
For examp le, the following will never throw an exception:
mxGetPr, mxGetData,
mxGetNumberOfDimensions, mxGetM, mxGetN,andmxGetNumberOfElements.
Code in run-time routines can also throw exceptions. Run-time routines refer
to certain S-function routine s that Simulink calls during the simulation loop
(see “The Cal ling Sequence for S-Functions” on page 3-16). The run-time
routines include:
•
mdlGetTimeOfNextVarHit
• mdlOutputs
• mdlUpdate
• mdlDerivatives
If all run-time routines within your S-function are e xception free, you can use
this option:
ssSetOptions(S, SS_OPTION_RUNTIME_EXCEPTION_FREE_CODE);
The other routines in your S-function do not have to be exception free.
ssSetErrorStatus Termination Criteria
When you call ssSetErrorStatus and return from your S-function, Simulink
stops the simulation and posts the error. To determine how the simulation
shuts down, refer to the flow chart figure on page 3-16. If
ssSetErrorStatus is
called prior to
mdlStart, no other S-function routine will be called. If
ssSetErrorStatus is called in mdlStart or later, mdlTerminate will be called.