Module trap

Source
Expand description

A trap represents an error which stores trace message with backtrace.

§Example

int main() {
    // Create an engine and a store.
    wasm_engine_t* engine = wasm_engine_new();
    wasm_store_t* store = wasm_store_new(engine);

    // Create the trap message.
    wasm_message_t message;
    wasm_name_new_from_string_nt(&message, "foobar");

    // Create the trap with its message.
    // The backtrace will be generated automatically.
    wasm_trap_t* trap = wasm_trap_new(store, &message);
    assert(trap);

    wasm_name_delete(&message);

    // Do something with the trap.

    // Free everything.
    wasm_trap_delete(trap);
    wasm_store_delete(store);
    wasm_engine_delete(engine);

    return 0;
}

Usually, a trap is returned from a host function (an imported function).

cbindgen:ignore

Structs§

wasm_trap_t

Functions§

wasm_trap_delete
Deletes a trap.
wasm_trap_message
Gets the message attached to the trap.
wasm_trap_new
Create a new trap message.
wasm_trap_origin
Gets the origin frame attached to the trap.
wasm_trap_trace
Gets the trace (as a list of frames) attached to the trap.