method fail
Documentation for method fail
assembled from the following types:
class Channel
From Channel
(Channel) method fail
Defined as:
method fail(Channel: )
Closes the Channel
(that is, makes subsequent send
calls die), and enqueues the error to be thrown as the final element in the channel. Method receive
will throw that error as an exception. Does nothing if the channel has already been closed or .fail
has already been called on it.
my = Channel.new;.fail("Bad error happens!");.receive;CATCH ;# OUTPUT: «X::AdHoc: Bad error happens!»
class Exception
From Exception
(Exception) method fail
Defined as:
multi sub fail(*)multi sub fail(Exception )method fail(Exception:)
Exits the calling Routine
and returns a Failure object wrapping the exception $e
- or, for the *@text
form, an X::AdHoc exception constructed from the concatenation of @text
. If the caller activated fatal exceptions via the pragma use fatal;
, the exception is thrown instead of being returned as a Failure
.
# A custom exception definedis Exceptionsub copy-directory-tree ()# A Failure with X::AdHoc exception object is returned and# assigned, so no throwing Would be thrown without an assignmentmy = copy-directory-tree("cat.jpg");say .exception; # OUTPUT: «cat.jpg is not a directory»# A Failure with a custom Exception object is returned= copy-directory-tree('foo');say .exception; # OUTPUT: «This directory is forbidden: 'foo'»