rethrow — Propagate a caught exception without handling it locally.
rethrow re-raises an exception so that an outer catch block or the embedding runtime can handle it. When you pass an MException, RunMat preserves its identifier and message. Passing a string creates a fresh error with that message. In Ignition-compiled catch blocks, rethrow() with no explicit argument also rethrows the most recently caught exception.
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.
How RunMat runs 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:
xFAQ
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 works, line by line, in Rust.
- View rethrow.rs on GitHub
- Learn how the 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 — faster, on any GPU, with no license required.
- Simulations that took hours now take minutes. RunMat automatically optimizes your math for GPU execution on Apple, Nvidia, and AMD hardware. No code changes needed.
- Start running code in seconds. Open the browser sandbox or download a single binary. No license server, no IT ticket, no setup.
- A full development environment. GPU-accelerated 2D and 3D plotting, automatic versioning on every save, and a browser IDE you can share with a link.