Writing S-Functions Previous page   Next Page

Handling Errors

When working with S-functions, it is important to handle unexpected events such as invalid parameter values correctly.

If your S-function has parameters whose contents you need to validate, use the following technique to report errors encountered.

Note that the second argument to ssSetErrorStatus must be persistent memory. It cannot be a local variable in your procedure. For example, the following causes unpredictable errors.

Because ssSetErrorStatus does not generate exceptions, using it to report errors in your S-function is preferable to using mexErrMsgTxt. The mexErrMsgTxt function uses exception handling to terminate S-function execution and return control to Simulink. To support exception handling in S-functions, Simulink must set up exception handlers prior to each S-function invocation. This introduces overhead into simulation.


Previous page  Processing Frame-Based Signals Exception Free Code Next page

© 1994-2005 The MathWorks, Inc.