1Error::TypeTiny(3) User Contributed Perl Documentation Error::TypeTiny(3)
2
3
4
6 Error::TypeTiny - exceptions for Type::Tiny and friends
7
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
24 This module is covered by the Type-Tiny stability policy.
25
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 Attributes
41 "message"
42 The error message.
43
44 "context"
45 Hashref containing the package, file and line that generated the
46 error.
47
48 "stack_trace"
49 A more complete stack trace. This feature requires
50 Devel::StackTrace; use the $StackTrace package variable to switch
51 it on.
52
53 Methods
54 "to_string"
55 Returns the message, followed by the context if it is set.
56
57 Functions
58 "Error::TypeTiny::croak($format, @args)"
59 Functional-style shortcut to "throw" method. Takes an
60 "sprintf"-style format string and optional arguments to construct
61 the "message".
62
63 Overloading
64 ยท Stringification is overloaded to call "to_string".
65
66 Package Variables
67 %Error::TypeTiny::CarpInternal
68 Serves a similar purpose to %Carp::CarpInternal.
69
70 $Error::TypeTiny::StackTrace
71 Boolean to toggle stack trace generation.
72
73 $Error::TypeTiny::LastError
74 A reference to the last exception object thrown.
75
77 Although Error::TypeTiny objects are thrown for errors produced by
78 Type::Tiny, that doesn't mean every time you use Type::Tiny you'll get
79 Error::TypeTinys whenever you want.
80
81 For example, if you use a Type::Tiny type constraint in a Moose
82 attribute, Moose will not call the constraint's "assert_valid" method
83 (which throws an exception). Instead it will call "check" and
84 "get_message" (which do not), and will "confess" an error message of
85 its own. (The $LastError package variable may save your bacon.)
86
88 Please report any bugs to
89 <http://rt.cpan.org/Dist/Display.html?Queue=Type-Tiny>.
90
92 Error::TypeTiny::Assertion, Error::TypeTiny::WrongNumberOfParameters.
93
94 Try::Tiny, Try::Tiny::ByClass.
95
97 Toby Inkster <tobyink@cpan.org>.
98
100 This software is copyright (c) 2013-2014, 2017-2019 by Toby Inkster.
101
102 This is free software; you can redistribute it and/or modify it under
103 the same terms as the Perl 5 programming language system itself.
104
106 THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
107 WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
108 MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
109
110
111
112perl v5.28.1 2019-01-08 Error::TypeTiny(3)