method fail

Documentation for method fail, assembled from the following types:

class Exception

From Exception

(Exception) method fail

Defined as:

multi sub    fail(*@text)
multi sub    fail(Exception $e)
method fail(Exception:D:)

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.

sub copy-directory-tree ($dir{
    fail "$dir is not a directory" if !$dir.IO.d;
    ...
}

class Channel

From Channel

(Channel) method fail

Defined as:

method fail(Channel:D: $error)

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 $c = Channel.new;
$c.fail("Bad error happens!");
$c.receive;
CATCH { default { put .^name''.Str } };
# OUTPUT: «X::AdHoc: Bad error happens!␤»