Bitcoin::Crypto::Exception - Exception classes for Bitcoin::Crypto
try { decode_segwit('Not a segwit address'); } catch ($error) { # $error is an instance of Bitcoin::Crypto::Exception and stringifies automatically warn "$error"; # it also contains some information about the problem to avoid regex matching if ($error->isa('Bitcoin::Crypto::Exception::Bech32InputFormat')) { log $error->message; } }
An exception wrapper class with automatic stringification and standarized raising.
Contains inline packages that identify parts that went wrong (like Bitcoin::Crypto::Exception::Sign for errors in signature generation). Search individual Bitcoin::Crypto packages documentation for a list the exception classes to check for extra control flow when needed.
Bitcoin::Crypto::Exception::Sign
The wrapped error message (a string). Note: this is the raw message, not the serialized form like in "as_string".
Not assignable in the constructor
An array ref containing: package name, file name and line number (same as [caller()] perl expression). It will point to the first place from outside Bitcoin::Crypto which called it. May be undefined if it cannot find a calling source.
[caller()]
$runner = Bitcoin::Crypto::Exception->new(%data)
This is a standard Moo constructor, which can be used to create the object. It takes arguments specified in "Attributes". For exceptions, it's probably better to use "raise" instead.
Returns class instance.
$error_info = $object->as_string()
Stringifies the error, using the "message" method, "caller" method and some extra text for context.
$object->raise() $class->raise($message)
Creates a new instance and throws it. If used on an object, throws it right away.
try { # throws, but will be catched Bitcoin::Crypto::Exception->raise('something went wrong'); } catch ($exception) { # throws again $exception->raise; }
An alias to raise.
raise
$sub_result = $class->trap_into($sub, $prefix)
Executes the given subroutine in an exception-trapping environment. Any exceptions thrown inside the subroutine $sub will be re-thrown after turning them into objects of the given ::Exception class. If no exception is thrown, method returns the value returned by $sub.
$sub
::Exception
my $result = Bitcoin::Crypto::Exception->trap_into(sub { die 'something went wrong'; });
$prefix can be specified to better format the message.
$prefix
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.