rethrow — Rethrow a caught exception so it propagates to an outer handler.
rethrow re-raises an exception so an outer catch block or embedding runtime can handle it. Passing an MException preserves identifier and message, while passing text creates a new error payload; rethrow() in a catch block rethrows the active exception context.
Syntax
rethrow(err)Inputs
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
err | Any | Yes | — | Error value to rethrow. |
How rethrow works
rethrow(err)preserves the identifier and message of anMExceptionvalue.rethrow(message)raises a fresh error using the supplied string as the message.- Other value types produce a generic
RunMat:error-style failure describing the value. rethrownever returns normally; it immediately transfers control outward to the next enclosing error handler.- In Ignition
catchblocks,rethrow()with no argument uses the most recently caught exception.
Does RunMat run rethrow on the GPU?
rethrow performs no provider dispatch; it raises or propagates a host-side runtime error immediately.
GPU memory and residency
rethrow is control flow only and never executes on the GPU.
Examples
Propagate an exception to an outer catch block
try
try
error("RunMat:demo:badInput", "Bad input.");
catch err
rethrow(err);
end
catch outer
disp(outer.identifier)
endExpected output:
RunMat:demo:badInputUse the no-argument shorthand inside an Ignition catch block
try
try
error("RunMat:oops", "x");
catch
rethrow();
end
catch err
disp(err.message)
endExpected output:
xUsing rethrow with coding agents
Open a RunMat example with live inputs, then ask the agent to explain how rethrow changes the result.
Run a small rethrow example, explain the result, then change one input and compare the output.
FAQ
When should I use rethrow instead of error?⌄
Use rethrow when you want to propagate the current exception rather than constructing a new one from scratch.
Does rethrow(err) preserve the original identifier?⌄
Yes. When err is an MException, RunMat preserves both the identifier and the message.
Is rethrow() without an argument supported?⌄
Yes in Ignition catch-block execution, where it reuses the most recently caught exception.
Related Diagnostics functions
Open-source implementation
Unlike proprietary runtimes, every RunMat function is open-source. Read exactly how rethrow is executed, line by line, in Rust.
- View the source for rethrow 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.