RunMat
GitHub

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

NameTypeRequiredDefaultDescription
errAnyYesError value to rethrow.

How rethrow works

  • rethrow(err) preserves the identifier and message of an MException value.
  • 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.
  • rethrow never returns normally; it immediately transfers control outward to the next enclosing error handler.
  • In Ignition catch blocks, 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)
end

Expected output:

RunMat:demo:badInput

Use the no-argument shorthand inside an Ignition catch block

try
    try
        error("RunMat:oops", "x");
    catch
        rethrow();
    end
catch err
    disp(err.message)
end

Expected output:

x

Using 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.

Open-source implementation

Unlike proprietary runtimes, every RunMat function is open-source. Read exactly how rethrow is executed, line by line, in Rust.

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.

Getting started · Benchmarks · Pricing

Download RunMat

Download RunMat for full performance, or use RunMat in your browser for zero setup.