Bitcoin-Crypto

 view release on metacpan or  search on metacpan

lib/Bitcoin/Crypto/Exception.pm  view on Meta::CPAN

Thrown when a general problem with a block is detected.

=head2 Bitcoin::Crypto::Exception::ScriptTree

Thrown when a general problem with a script tree is detected.

=head2 Bitcoin::Crypto::Exception::ScriptCompilation

Thrown when a script compilation fails. It can only be thrown just
before the script is executed.

=head2 Bitcoin::Crypto::Exception::ScriptRuntime

Thrown when an error occurs during script runtime.

=head2 Bitcoin::Crypto::Exception::TransactionScript

Thrown when an error occurs in execution of scripts during
transaction validation. Subclass of
L</Bitcoin::Crypto::Exception::Transaction> and
L</Bitcoin::Crypto::Exception::ScriptRuntime>.

=head2 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.

=head2 Bitcoin::Crypto::Exception::NetworkConfig

Thrown when network configuration is bad or insufficient to perform
the operation.

=head2 Bitcoin::Crypto::Exception::Address

Thrown when a general error connected to addresses is encountered.

=head2 Bitcoin::Crypto::Exception::AddressGenerate

Thrown when an error is encountered while generating an address. Subclass of
L</Bitcoin::Crypto::Exception::Address>.

=head2 Bitcoin::Crypto::Exception::PSBT

Thrown when a problem with PSBT format was encountered.

=head1 INTERFACE

=head2 Attributes

=head3 message

The wrapped error message (a string). Note: this is the raw message,
not the serialized form like in L</as_string>.

=head3 caller

B<Not assignable in the constructor>

An array ref containing: package name, file name and line number (same
as C<[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.

=head2 Methods

=head3 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 L</Attributes>. For exceptions, it's probably
better to use L</raise> instead.

Returns class instance.

=head3 as_string

	$error_info = $object->as_string()

Stringifies the error, using the L</message> method, L</caller> method and some
extra text for context.

=head3 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;
	}

=head3 throw

An alias to C<raise>.

=head3 trap_into

	$sub_result = $class->trap_into($sub, $prefix)

Executes the given subroutine in an exception-trapping environment. Any
exceptions thrown inside the subroutine C<$sub> will be re-thrown after turning
them into objects of the given C<::Exception> class. If no exception is thrown,
method returns the value returned by C<$sub>.

	my $result = Bitcoin::Crypto::Exception->trap_into(sub {
		die 'something went wrong';
	});

C<$prefix> can be specified to better format the message.



( run in 0.857 second using v1.01-cache-2.11-cpan-75ffa21a3d4 )