Wasm::Trap - Wasm trap class
my $trap = Wasm::Trap->new(
"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 thrown into or out of WebAssembly. It can be thrown back to WebAssembly via die in a Perl function called from WebAssembly. It can be caught in Perl via eval around WebAssembly.
The actual implementation may be a super or subclass. As of this writing it is a simple wrapper around Wasm::Wasmtime::Trap, but relying on that is undefined behavior. In order to catch a trap from WebAssembly, use this class name like so:
use Ref::Util qw( is_blessed_ref );
local $@ = '';
if(my $error = $@)
if(is_blessed_ref $error && $error->isa('Wasm::Trap'))
my $message = $error->message;
my $exit_value = $error->exit_value;
print "message = $message\n";
print "exit_value = $exit_value\n";
To throw from Perl:
my $trap = Wasm::Trap->new($message);
This creates a new trap object.
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 will return the exist status code. If it wasn't triggered by an exit call it will return undef.
Graham Ollis <email@example.com>
This software is copyright (c) 2020-2022 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.
To install Wasm, copy and paste the appropriate command in to your terminal.
perl -MCPAN -e shell
For more information on module installation, please visit the detailed CPAN module installation guide.