Function wasmer_c_api::wasm_c_api::trap::wasm_trap_message

source ·
#[no_mangle]
pub unsafe extern "C" fn wasm_trap_message(
    trap: &wasm_trap_t,
    out: &mut wasm_byte_vec_t,
)
Expand description

Gets the message attached to the trap.

§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);

    // Get the trap's message back.
    wasm_message_t retrieved_message;
    wasm_trap_message(trap, &retrieved_message);
    assert(retrieved_message.size == message.size);

    // Free everything.
    wasm_name_delete(&message);
    wasm_name_delete(&retrieved_message);
    wasm_trap_delete(trap);
    wasm_store_delete(store);
    wasm_engine_delete(engine);

    return 0;
}