NAME
Bitcoin::Crypto::Exception - Exception classes for Bitcoin::Crypto
SYNOPSIS
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;
}
}
DESCRIPTION
An exception wrapper class with automatic stringification and standardized 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.
EXCEPTION SUBCLASSES
This module defines the following subclasses to Bitcoin::Crypto::Exception:
Bitcoin::Crypto::Exception::Transaction
Thrown when a general problem with a transaction is detected, for example: non-script verification failure, corrupted serialized transaction data.
Bitcoin::Crypto::Exception::UTXO
Thrown when a problem with UTXO is detected, most notably inability to find the UTXO.
Bitcoin::Crypto::Exception::Sign
Thrown when a problem occurs during signing a transaction or message.
Bitcoin::Crypto::Exception::KeyCreate
Thrown when a problem occurs during creation of a key.
Bitcoin::Crypto::Exception::KeyDerive
Thrown when a problem occurs during derivation of a key.
Bitcoin::Crypto::Exception::MnemonicCheck
Thrown when a mnemonic checking was unsuccessful.
Bitcoin::Crypto::Exception::Base58
Thrown when a general base58 format problem is detected.
Bitcoin::Crypto::Exception::Base58InputFormat
Thrown when input does not look like valid base58. Subclass of "Bitcoin::Crypto::Exception::Base58".
Bitcoin::Crypto::Exception::Base58InputChecksum
Thrown when base58check input checksum is invalid. Subclass of "Bitcoin::Crypto::Exception::Base58".
Bitcoin::Crypto::Exception::Bech32
Thrown when a general Bech32 format problem is detected.
Bitcoin::Crypto::Exception::Bech32InputFormat
Thrown when input does not look like valid bech32. Subclass of "Bitcoin::Crypto::Exception::Bech32".
Bitcoin::Crypto::Exception::Bech32InputData
Thrown when input is valid bech32, but contains invalid data. Subclass of "Bitcoin::Crypto::Exception::Bech32".
Bitcoin::Crypto::Exception::Bech32InputChecksum
Thrown when bech32 input checksum is invalid. Subclass of "Bitcoin::Crypto::Exception::Bech32".
Bitcoin::Crypto::Exception::SegwitProgram
Thrown when an issue with Segregated Witness program is detected.
Bitcoin::Crypto::Exception::ScriptType
Thrown when an unexpected script type is encountered.
Bitcoin::Crypto::Exception::ScriptOpcode
Thrown when unexpected script operation is encountered.
Bitcoin::Crypto::Exception::ScriptPush
Thrown when bad script push operation is performed.
Bitcoin::Crypto::Exception::Block
Thrown when a general problem with a block is detected.
Bitcoin::Crypto::Exception::ScriptTree
Thrown when a general problem with a script tree is detected.
Bitcoin::Crypto::Exception::ScriptCompilation
Thrown when a script compilation fails. It can only be thrown just before the script is executed.
Bitcoin::Crypto::Exception::ScriptRuntime
Thrown when an error occurs during script runtime.
Bitcoin::Crypto::Exception::TransactionScript
Thrown when an error occurs in execution of scripts during transaction validation. Subclass of "Bitcoin::Crypto::Exception::Transaction" and "Bitcoin::Crypto::Exception::ScriptRuntime".
Bitcoin::Crypto::Exception::NetworkCheck
Thrown when an assumption about network is not met. This can happen in single-network mode or if a network parameter is used, but it does not match the arguments.
Bitcoin::Crypto::Exception::NetworkConfig
Thrown when network configuration is bad or insufficient to perform the operation.
Bitcoin::Crypto::Exception::Address
Thrown when a general error connected to addresses is encountered.
Bitcoin::Crypto::Exception::AddressGenerate
Thrown when an error is encountered while generating an address. Subclass of "Bitcoin::Crypto::Exception::Address".
Bitcoin::Crypto::Exception::PSBT
Thrown when a problem with PSBT format was encountered.
INTERFACE
Attributes
message
The wrapped error message (a string). Note: this is the raw message, not the serialized form like in "as_string".
caller
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.
Methods
new
$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.
as_string
$error_info = $object->as_string()
Stringifies the error, using the "message" method, "caller" method and some extra text for context.
raise
$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;
}
throw
An alias to raise.
trap_into
$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.
my $result = Bitcoin::Crypto::Exception->trap_into(sub {
die 'something went wrong';
});
$prefix can be specified to better format the message.