1Future::Exception(3)  User Contributed Perl Documentation Future::Exception(3)
2
3
4

NAME

6       "Future::Exception" - an exception type for failed Futures
7

SYNOPSIS

9          use Scalar::Util qw( blessed );
10          use Syntax::Keyword::Try;
11
12          try {
13             my $f = ...;
14             my @result = $f->result;
15             ...
16          }
17          catch {
18             if( blessed($@) and $@->isa( "Future::Exception" ) {
19                print STDERR "The ", $@->category, " failed: ", $@->message, "\n";
20             }
21          }
22

DESCRIPTION

24       The "get" method on a failed Future instance will throw an exception to
25       indicate that the future failed. A failed future can contain a failure
26       category name and other details as well as the failure message, so in
27       this case the exception will be an instance of "Future::Exception" to
28       make these values accessible.
29
30       Users should not depend on exact class name matches, but instead rely
31       on inheritence, as a later version of this implementation might
32       dynamically create subclasses whose names are derived from the Future
33       failure category string, to assist with type matching. Note the use of
34       "->isa" in the SYNOPSIS example.
35

CONSTRUCTOR

37   from_future
38          $e = Future::Exception->from_future( $f )
39
40       Constructs a new "Future::Exception" wrapping the given failed future.
41

ACCESSORS

43          $message  = $e->message
44          $category = $e->category
45          @details  = $e->details
46
47       Additionally, the object will stringify to return the message value,
48       for the common use-case of printing, regexp testing, or other
49       behaviours.
50

METHODS

52   throw
53          Future::Exception->throw( $message, $category, @details )
54
55       Since version 0.41.
56
57       Constructs a new exception object and throws it using "die()". This
58       method will not return, as it raises the exception directly.
59
60       If $message does not end in a linefeed then the calling file and line
61       number are appended to it, in the same way "die()" does.
62
63   as_future
64          $f = $e->as_future
65
66       Returns a new "Future" object in a failed state matching the exception.
67

AUTHOR

69       Paul Evans <leonerd@leonerd.org.uk>
70
71
72
73perl v5.32.1                      2021-01-27              Future::Exception(3)
Impressum