Skip to main content

throw_error

Function throw_error 

Source
pub fn throw_error(caller: &mut Caller<'_, StoreData>, message: &str) -> Error
Expand description

Raise a catchable Submilli Error from inside a host function.

Host-function failures normally surface as Wasm traps, which try/catch cannot intercept. This allocates the $Error directly (same construction as the host Error constructor), wraps it in an exception object for the host-owned tag, and throws it via the store — the engine unwinds to the nearest try_table in the calling Wasm frame. register_host_fn wraps every host body so any returned Err routes through here automatically; the caller must return Err(..) the result unchanged.

Always returns an Err-carrying value. Before the prelude instantiates (host_abi unset) it falls back to a plain-message error — an uncatchable trap with the right text, matching the pre-catchable behavior.