error — Throw an error with optional identifier and formatted message values.
error constructs a diagnostic message and transfers control to the nearest compatible catch boundary. A one-input message is literal; multi-input forms decode documented escapes and apply sprintf-style formatting before throwing.
Syntax
error(msg)
error(msg, A)
error(errID, ___)
error(errorStruct)
error(correction, ___)Inputs
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
message | StringScalar | Yes | — | Error message text. |
message | StringScalar | Yes | — | Error message template text. |
A | Any | Variadic | — | Formatting values for the message template. |
message_id | StringScalar | Yes | — | Message identifier. |
msg_struct | Any | Yes | — | Struct containing identifier/message fields. |
correction | Any | Yes | — | MATLAB correction object. |
messageArguments | Any | Variadic | — | Identifier, message, and optional formatting values. |
Errors
| Identifier | When | Message |
|---|---|---|
RunMat:error | No arguments are supplied. | error: missing message argument |
RunMat:error | Additional arguments are supplied after an MException input. | error: additional arguments are not allowed when passing an MException |
RunMat:error | Additional arguments are supplied after a message-struct input. | error: additional arguments are not allowed when passing a message struct |
RunMat:error | Message struct contains none of message, identifier, or stack. | error: message struct must contain 'message', 'identifier', or 'stack' |
RunMat:error | Message struct requests an explicit MATLAB stack that cannot be represented yet. | error: explicit errorStruct stack is not supported yet |
RunMat:error | Identifier/message inputs or format arguments are not string-compatible. | error: invalid input argument |
RunMat:error | Identifier fields do not follow documented colon-separated identifier grammar. | error: invalid error identifier |
RunMat:error | A documented matlab.lang.correction object is supplied before correction objects are representable. | error: matlab.lang.correction objects are not supported yet |
How error works
error(msg)throws the literal text scalar without converting escape or format sequences.error(msg,A)anderror(errID,___)decode escape sequences, format replacement values, and then throw.- Documented error identifiers use colon-separated fields that each begin with a letter and otherwise contain only letters, digits, or underscores.
- All eight integer classes are documented numeric formatting values. RunMat keeps typed integers authoritative through integer conversion specifiers, including
uint64values above binary64's exact range. - If every supplied input is an empty array, the call is a no-op and does not throw.
error(MException), unqualified identifier normalization, and themessageidormsgstructure aliases are independent RunMat-only extensions and reject in MATLAB compatibility mode.- The documented matlab.lang.correction object families are not yet representable in RunMat and currently raise an explicit unsupported diagnostic.
- An errorStruct can use message and identifier fields independently. Explicit errorStruct stack reconstruction is deferred because RuntimeError does not yet accept MATLAB stack structures.
GPU memory and residency
Formatting values gather to host after message and identifier validation; error is a host control-flow operation.
Examples
Throw a formatted error with an identifier
error('MyComponent:incorrectType','Input must be a char, not a %s.',class(x))Expected output:
Throws an exception with identifier `MyComponent:incorrectType`.Format an exact typed integer
error('Value is %u',uint64(18446744073709551615))Expected output:
The integer conversion uses authoritative uint64 storage before the diagnostic is thrown.Using error with coding agents
Open a RunMat example with live inputs, then ask the agent to explain how error changes the result.
Run a small error example, explain the result, then change one input and compare the output.
FAQ
Does error execute on the GPU?⌄
No. MathWorks documents GPU-array inputs, but the function does not run on the GPU. RunMat gathers valid formatting values and throws from the host.
Are suggested corrections implemented?⌄
Not yet. RunMat does not currently model the three matlab.lang.correction object classes, so correction-object calls report the infrastructure gap explicitly.
Does errorStruct preserve an explicit stack?⌄
Not yet. Message and identifier fields are supported, but translating MATLAB stack structure arrays into RuntimeError call frames remains deferred.
Related Diagnostics functions
Open-source implementation
Unlike proprietary runtimes, every RunMat function is open-source. Read exactly how error is executed, line by line, in Rust.
- View the source for error in Rust on GitHub
- Learn how the RunMat runtime works
- Found a bug? Open an issue with a minimal reproduction.
About RunMat
RunMat is an open-source runtime that executes MATLAB-syntax code blazing on any GPU. It is licensed under the Apache 2.0 license.
- RunMat automatically optimizes your math for GPU execution on Apple, Nvidia, and AMD hardware. No code changes needed. Simulations that took hours now take minutes.
- Start running code in seconds. RunMat runs in the browser, on the desktop, or from the CLI. No license server, no IT ticket.