Wasm::Wasmtime::Trap - Wasmtime trap class
version 0.24
use Wasm::Wasmtime; my $store = Wasm::Wasmtime::Store->new; my $trap = Wasm::Wasmtime::Trap->new( $store, "something went bump in the night\0", );
WARNING: WebAssembly and Wasmtime are a moving target and the interface for these modules is under active development. Use with caution.
This class represents a trap, usually something unexpected that happened in Wasm land. This is usually converted into an exception in Perl land, but you can create your own trap here.
my $trap = Wasm::Wasmtime::Trap->new($message); my $trap = Wasm::Wasmtime::Trap->new($store, $message); # $store is ignored
Create a trap instance. In the modern Wasmtime API traps are not associated with a store, so the $store argument (if given, for backwards compatibility) is ignored.
my $trap = Wasm::Wasmtime::Trap->from_error($error);
Creates a trap from a Wasm::Wasmtime::Error, carrying over its message and (if present) its WASI exit status.
my $message = $trap->message;
Returns the trap message as a string.
my $status = $trap->exit_status;
If the trap was triggered by an exit call this returns the exit status code, otherwise undef. In the modern Wasmtime API exit status is carried by the error rather than the trap, so this is populated by Wasm::Wasmtime when it converts an error into a trap and is undef otherwise.
my $code = $trap->code;
Returns the numeric instruction trap code, or undef if this is not an instruction trap.
Graham Ollis <plicease@cpan.org>
This software is copyright (c) 2020-2026 by Graham Ollis.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.