Bitcoin::Crypto::Exception - Exception class for Bitcoin::Crypto purposes
use Try::Tiny; try { decode_segwit("Not a segwit address"); } catch { my $error = $_; # $error is an instance of Bitcoin::Crypto::Exception and stringifies automatically warn "$error"; # but also contains some information about the problem to avoid regex matching if ($error->isa("Bitcoin::Crypto::Exception::Bech32InputFormat")) { log $error->message; } };
A wrapper class with automatic stringification and standarized raising. Contains many other inline packages that identify parts that went wrong (like Bitcoin::Crypto::Exception::Sign for errors in signature generation). See individual Bitcoin::Crypto packages documentation to see the exception classes to check for extra control flow when needed.
$error_string = $object->message()
Returns the error message (a string).
$caller_aref = $object->caller()
Returns an array ref containing: package name, file name and line number (same as [caller()] perl expression). It will contain the data for the first code from outside Bitcoin::Crypto which called it. May be undefined if it cannot find a calling source.
[caller()]
$error_info = $object->as_string()
Stringifies the error, using the message method, caller method and some extra text for context.
message
caller
$object->raise() $class->raise($message)
Creates a new instance and throws it. If used on an object, throws it right away.
use Try::Tiny; try { # throws, but will be catched Bitcoin::Crypto::Exception->raise("something went wrong"); } catch { my $exception = $_; # throws again $exception->raise; };
An alias to raise.
raise
$sub_result = $class->trap_into($sub)
Executes the subroutine given as the only parameter inside an eval. Any exceptions thrown inside the subroutine $sub will be re-thrown after turning them into objects of the given class. If no exception is thrown, method returns the value returned by $sub.
eval
$sub
my $result = Bitcoin::Crypto::Exception->trap_into(sub { die "something went wrong"; });
To install Bitcoin::Crypto, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Bitcoin::Crypto
CPAN shell
perl -MCPAN -e shell install Bitcoin::Crypto
For more information on module installation, please visit the detailed CPAN module installation guide.