warning — Emit formatted warnings and control warning state by identifier.
warning emits non-fatal diagnostic messages and manages warning enable/disable/error states globally or per identifier, following MATLAB-compatible control forms.
Syntax
state = warning()
state = warning(message)
state = warning(message, A...)
state = warning(message_id, message)
state = warning(message_id, message, A...)
state = warning(state)All supported warning forms
state = warning()
state = warning(message)
state = warning(message, A...)
state = warning(message_id, message)
state = warning(message_id, message, A...)
state = warning(state)
state = warning(mode)
state = warning(mode, target)
state = warning("default")
state = warning("default", target)
state = warning("reset")
state = warning("query")
state = warning("query", target)
state = warning("status")
state = warning("backtrace")
state = warning("backtrace", state)
state = warning(mex)Inputs
message- Type
StringScalar- Required
- Yes
- Description
- Warning message text or command token.
message- Type
StringScalar- Required
- Yes
- Description
- Warning message template text.
A- Type
Any- Required
- Variadic
- Description
- Formatting values for the warning message template.
message_id- Type
StringScalar- Required
- Yes
- Default
"RunMat:warning"- Description
- Warning identifier.
message- Type
StringScalar- Required
- Yes
- Description
- Warning message text.
state- Type
Any- Required
- Yes
- Description
- State struct/cell snapshot to restore.
mode- Type
StringScalar- Required
- Yes
- Description
- Mode token ('on','off','once','error','default','reset','query','status','backtrace').
mode- Type
StringScalar- Required
- Yes
- Description
- Mode token.
target- Type
StringScalar- Required
- Yes
- Default
"all"- Description
- Identifier/special target for mode updates or queries.
command- Type
StringScalar- Required
- Yes
- Default
"backtrace"- Description
- Backtrace command token.
state- Type
StringScalar- Required
- Yes
- Default
"off"- Description
- Backtrace state ('on' or 'off').
Returns
state_or_status- Type
Any- Description
- Numeric success sentinel or state/status struct/cell/string result.
Errors
RunMat:warning- When
- Arguments are invalid for the warning parser branch or command contract.
- Message
warning: invalid input arguments
RunMat:warning- When
- Warning mode is configured to promote warnings to errors.
- Message
warning: promoted to error
Behavior and placement
warning(message) prints the message using the default identifier RunMat:warning.
warning(id, fmt, args...) associates the warning with the identifier id, formats the message using MATLAB's sprintf rules, and honours per-identifier state.
Numeric scalar formatting values include every integer class and are formatted from authoritative storage, so wide signed and unsigned values remain exact.
Nonscalar integer formatting arrays are a gated RunMat extension and are consumed in column-major order.
warning(MException_obj) reissues an existing exception as a warning.
warning(struct) restores warning state previously captured with warning('query', ...).
warning(state, id) changes the mode for id ('on', 'off', 'once', 'error', and the aliases 'all' or 'last'). The call returns a struct describing the prior state so you can restore it later.
warning(state, mode) controls diagnostic verbosity modes such as 'backtrace' and 'verbose', returning a struct snapshot of the previous setting.
warning('default', id) resets id (or 'all', 'backtrace', 'verbose', 'last') to the factory default, returning the state that was active before the reset. warning('reset') restores every warning, mode, and once-tracking flag in one call.
warning('query', id) returns a struct describing the current mode for id. Passing 'all' returns a cell vector of structs covering every configured identifier plus the global default and diagnostic modes.
warning('status') prints the global warning table as a formatted summary.
All state-changing forms return struct snapshots; pass them back to warning later to reinstate the captured state.
warning is a control-flow builtin that runs on the host. Resident formatting arguments are rejected without launching a provider operation.
No GPU kernel or automatic gather is used by warning.
Examples
Displaying a simple warning
warning("Computation took longer than expected.")
last = warning('query', 'last');Emitting a warning with a custom identifier
warning("runmat:io:deprecatedOption", ...
"Option '%s' is deprecated and will be removed in %s.", ...
"VerboseMode", "1.2")
last = warning('query', 'last');Turning a specific warning off and back on
warning("off", "runmat:io:deprecatedOption");
% ... code that triggers the warning ...
warning("on", "runmat:io:deprecatedOption")
state = warning('query', 'runmat:io:deprecatedOption');Promoting a warning to an error
warning("error", "runmat:solver:illConditioned");
% The next call raises an error instead of printing a warning.
warning("runmat:solver:illConditioned", ...
"Condition number exceeds threshold %.2e.", 1e12)Querying and restoring warning state
state = warning("query", "all"); % capture the current table
warning("off", "all"); % silence all warnings temporarily
warning("Some temporary warning.");
warning(state); % restore original configuration
restored = warning('query', 'all');Enabling backtraces for debugging
warning("on", "backtrace"); % warning("backtrace","on") is equivalent
warning("runmat:demo:slowPath", "Inspect the call stack above for context.");
during = warning('query', 'backtrace');
warning("off", "backtrace")Displaying verbose suppression guidance
warning("on", "verbose");
warning("runmat:demo:slowPath", "Inspect the call stack above for context.");
during = warning('query', 'verbose');
warning("default", "verbose"); % restore the default verbosityUsing warning with coding agents
Open a RunMat example with live inputs, then ask the agent to explain how warning changes the result.
Run a small warning example, explain the result, then change one input and compare the output.
FAQ
Does RunMat keep track of the last warning?⌄
Yes. The last identifier and message are stored internally and will be exposed through the MATLAB-compatible lastwarn builtin.
What does 'once' do?⌄
The first occurrence of the warning is shown, and subsequent uses of the same identifier are suppressed until you change the state.
How do I restore defaults after experimentation?⌄
Call warning('reset') to revert the global default, per-identifier table, diagnostic modes, and once-tracking.
Do state-changing calls return anything useful?⌄
Yes. Forms such as warning('off','id'), warning('on','backtrace'), and warning('default') return struct snapshots describing the state before the change. Store the struct and pass it back to warning later to restore the captured configuration.
What does the 'verbose' mode do?⌄
When enabled (warning('on','verbose')), RunMat prints an additional hint describing how to suppress the warning. Disable it with warning('default','verbose').
What happens when a warning is promoted to 'error'?⌄
The warning text is reused to raise an error with the same identifier, just like MATLAB.
Does warning run on the GPU?⌄
No. Control-flow builtins execute on the host, and resident formatting values are rejected rather than gathered implicitly.
Can I provide multiple state structs to warning(state)?⌄
Yes. Pass either a struct or a cell array of structs (as returned by warning('query','all')); RunMat applies them sequentially.
Does warning('on','backtrace') match MATLAB output exactly?⌄
RunMat prints a Rust backtrace for now. Future releases will map this to MATLAB-style stack frames, but the enable/disable semantics match MATLAB.
Is whitespace in identifiers allowed?⌄
Identifiers follow MATLAB rules: they must contain at least one colon and no whitespace. RunMat normalises bare names by prefixing RunMat:.
What if I call warning with unsupported arguments?⌄
RunMat issues a MATLAB-compatible usage error so you can correct the call.
Are repeated calls thread-safe?⌄
Warning policy is scoped to the active runtime context, with a thread-local fallback outside one; calls do not share a process-global mutex-protected warning table.
Related Diagnostics functions
Source you can read
Every RunMat function's source is public. Read exactly how warning is executed, line by line, in Rust.
- View the source for warning in Rust on GitHub
- Learn how the RunMat runtime works
- Found a bug? Open an issue with a minimal reproduction.
About RunMat
RunMat is a runtime that executes MATLAB-syntax code fast on any GPU. The runtime is free for individuals, including freelancers; students and faculty at an academic institution, for teaching or research there; contributors to an open-source project, for work on that project; organizations with 250 or fewer people and US$10M or less in annual revenue; and anyone, for non-production use. See runmat.com/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.