1Template::Exception(3)User Contributed Perl DocumentationTemplate::Exception(3)
2
3
4
6 Template::Exception - Exception handling class module
7
9 use Template::Exception;
10
11 my $exception = Template::Exception->new($type, $info);
12 $type = $exception->type;
13 $info = $exception->info;
14 ($type, $info) = $exception->type_info;
15
16 print $exception->as_string();
17
18 $handler = $exception->select_handler(\@candidates);
19
21 The "Template::Exception" module defines an object class for
22 representing exceptions within the template processing life cycle.
23 Exceptions can be raised by modules within the Template Toolkit, or can
24 be generated and returned by user code bound to template variables.
25
26 Exceptions can be raised in a template using the "THROW" directive,
27
28 [% THROW user.login 'no user id: please login' %]
29
30 or by calling the throw() method on the current Template::Context
31 object,
32
33 $context->throw('user.passwd', 'Incorrect Password');
34 $context->throw('Incorrect Password'); # type 'undef'
35
36 or from Perl code by calling "die()" with a "Template::Exception"
37 object,
38
39 die (Template::Exception->new('user.denied', 'Invalid User ID'));
40
41 or by simply calling "die()" with an error string. This is
42 automagically caught and converted to an exception of '"undef"' type
43 (that's the literal string '"undef"' rather than Perl's undefined
44 value) which can then be handled in the usual way.
45
46 die "I'm sorry Dave, I can't do that";
47
48 Each exception is defined by its type and a information component (e.g.
49 error message). The type can be any identifying string and may contain
50 dotted components (e.g. '"foo"', '"foo.bar"', '"foo.bar.baz"').
51 Exception types are considered to be hierarchical such that '"foo.bar"'
52 would be a specific type of the more general '"foo"' type.
53
55 type()
56 Returns the exception type.
57
58 info()
59 Returns the exception information.
60
62 Andy Wardley <abw@wardley.org> <http://wardley.org/>
63
65 Copyright (C) 1996-2007 Andy Wardley. All Rights Reserved.
66
67 This module is free software; you can redistribute it and/or modify it
68 under the same terms as Perl itself.
69
71 Template, Template::Context
72
73
74
75perl v5.36.0 2022-07-22 Template::Exception(3)