1Error::TypeTiny(3)    User Contributed Perl Documentation   Error::TypeTiny(3)
2
3
4

NAME

6       Error::TypeTiny - exceptions for Type::Tiny and friends
7

SYNOPSIS

9          use Data::Dumper;
10          use Try::Tiny;
11          use Types::Standard qw(Str);
12
13          try {
14             Str->assert_valid(undef);
15          }
16          catch {
17             my $exception = shift;
18             warn "Encountered Error: $exception";
19             warn Dumper($exception->explain)
20                if $exception->isa("Error::TypeTiny::Assertion");
21          };
22

STATUS

24       This module is covered by the Type-Tiny stability policy.
25

DESCRIPTION

27       When Type::Tiny and its related modules encounter an error, they throw
28       an exception object. These exception objects inherit from
29       Error::TypeTiny.
30
31   Constructors
32       "new(%attributes)"
33           Moose-style constructor function.
34
35       "throw(%attributes)"
36           Constructs an exception and passes it to "die".
37
38           Automatically populates "context" and "stack_trace" if appropriate.
39
40       "throw_cb($callback, %attributes)"
41           Constructs an exception and passes it to $callback which should be
42           a coderef; if undef, uses "die".
43
44           Automatically populates "context" and "stack_trace" if appropriate.
45
46   Attributes
47       "message"
48           The error message.
49
50       "context"
51           Hashref containing the package, file and line that generated the
52           error.
53
54       "stack_trace"
55           A more complete stack trace. This feature requires
56           Devel::StackTrace; use the $StackTrace package variable to switch
57           it on.
58
59   Methods
60       "to_string"
61           Returns the message, followed by the context if it is set.
62
63   Functions
64       "Error::TypeTiny::croak($format, @args)"
65           Functional-style shortcut to "throw" method. Takes an
66           "sprintf"-style format string and optional arguments to construct
67           the "message".
68
69   Overloading
70       •   Stringification is overloaded to call "to_string".
71
72   Package Variables
73       %Carp::CarpInternal
74           Error::TypeTiny honours this package variable from Carp.  (
75           %Error::TypeTiny::CarpInternal is an alias for it.)
76
77       $Error::TypeTiny::StackTrace
78           Boolean to toggle stack trace generation.
79
80       $Error::TypeTiny::LastError
81           A reference to the last exception object thrown.
82

CAVEATS

84       Although Error::TypeTiny objects are thrown for errors produced by
85       Type::Tiny, that doesn't mean every time you use Type::Tiny you'll get
86       Error::TypeTinys whenever you want.
87
88       For example, if you use a Type::Tiny type constraint in a Moose
89       attribute, Moose will not call the constraint's "assert_valid" method
90       (which throws an exception). Instead it will call "check" and
91       "get_message" (which do not), and will "confess" an error message of
92       its own. (The $LastError package variable may save your bacon.)
93

BUGS

95       Please report any bugs to
96       <https://github.com/tobyink/p5-type-tiny/issues>.
97

SEE ALSO

99       Error::TypeTiny::Assertion, Error::TypeTiny::WrongNumberOfParameters.
100
101       Try::Tiny, Try::Tiny::ByClass.
102

AUTHOR

104       Toby Inkster <tobyink@cpan.org>.
105
107       This software is copyright (c) 2013-2014, 2017-2023 by Toby Inkster.
108
109       This is free software; you can redistribute it and/or modify it under
110       the same terms as the Perl 5 programming language system itself.
111

DISCLAIMER OF WARRANTIES

113       THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
114       WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
115       MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
116
117
118
119perl v5.36.0                      2023-01-04                Error::TypeTiny(3)
Impressum