error
Raise an error message.
📝Syntax
error(id, msg)
error(id, msg, A, ...)
error(msg)
error(msg, A, ...)
error(error_structure)
error(correction, ...)
📥Input Arguments
Parameter Description
id a string: error identifier.
msg a string: message or format.
A values used to format the message.
error_structure scalar error message structure with message, identifier, or stack fields.
correction a nelson.lang.correction object.
📄Description

error stops the current script execution.

error(' ') will be ignored and the script will continue to run.

error(msg, A, ...) and error(id, msg, A, ...) format the message with the same rules as sprintf.

error(error_structure) accepts a scalar structure. Missing fields are treated as empty values, and additional fields are ignored.

When error_structure.stack is supplied, only the file, name, and line fields are used. Additional stack fields are ignored. Noninteger line values use their real integer part; invalid numeric values use 0.

error(correction, ...) stores the correction object in the thrown MException.

identifier includes one or more component fields and a mnemonic field (example: 'nelson:matrix:empty')

How to build an error identifier. An identifier is written component:mnemonic, with one or more component fields followed by a mnemonic, each field starting with a letter and containing only letters, digits, or underscores, separated by colons (example: 'Nelson:elementary_functions:notFinite'). Identifiers thrown by Nelson itself use Nelson as the first component; in your own code use a component of your choosing (for example your module or toolbox name).

A few rules keep identifiers useful:

- The component should route to the area that raises the error (a module, class, or function name); the mnemonic should name the specific check in camelCase (example: 'mustBeFinite', 'tooManyInputs').

- For errors that can happen anywhere (argument count, indexing, an expected value shape), a short two-field identifier is enough (example: 'Nelson:tooManyInputs', 'Nelson:badsubscript').

- Give one identifier a single message text: an identifier reused with several different messages cannot be translated and is dropped from the message catalog.

- Reuse an existing identifier for the same condition rather than creating a near-duplicate, and keep the mnemonic stable and descriptive (do not encode a run-time value in it).

💡Examples
error('your error message.')
error('nelson:identifier', 'your error message.')
error('Value %d', 7)
error('')
 1 / [1 2 3]
a = lasterror()
lasterror('reset')
b = lasterror()
error(a)
c = lasterror()
🔗See Also
MExceptionlasterrorwarning
🕔Version History
Version Description
1.0.0 initial version
Edit this page on GitHub