Target Language Compiler    

Fatal (Internal) TLC Coding Errors

Suppose you have an S-function that has a local function that can accept only numerical numbers. You may want to add an assert requiring that the inputs be only numerical numbers. These asserts indicate fatal coding errors in that the user has no way of building a model or specifying attributes that can cause the error to occur.

Using Library Functions

The two available library functions are

where block is the offending block record (or [] if the block is already scoped), and

for error messages that are not block specific. For example, to add assert code you could use

These library functions prepend the string Real-Time Workshop Fatal to the message you provide and display the call stack when reporting the error.

For an example usage of these functions, refer to gensfun.tlc for block errors and commonsetup.tlc for common errors. There are other files that use these functions in the directory matlabroot/rtw/c/tlc.

Using %exit

You can call %exit to generate fatal error messages, however, it is suggested that you use one of the previously discussed library functions. If you do use %exit, take care when generating an error string containing new lines (carriage returns); see Formatting Error Messages.

When generating fatal error messages directly with %exit, it is good practice to give a stack trace with the error message. This lets you see the call chain of functions that caused the error. To generate a stack trace, generate the message using the format


  TLC Error Handling Formatting Error Messages