1Template::Exception(3)User Contributed Perl DocumentationTemplate::Exception(3)
2
3
4

NAME

6       Template::Exception - Exception handling class module
7

SYNOPSIS

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

DESCRIPTION

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" object,
37
38           die (Template::Exception->new('user.denied', 'Invalid User ID'));
39
40       or by simply calling die() with an error string.  This is automagically
41       caught and converted to an  exception of '"undef"' type (that's the
42       literal string '"undef"' rather than Perl's undefined value) which can
43       then be handled in the usual way.
44
45           die "I'm sorry Dave, I can't do that";
46
47       Each exception is defined by its type and a information component (e.g.
48       error message).  The type can be any identifying string and may contain
49       dotted components (e.g. '"foo"', '"foo.bar"', '"foo.bar.baz"').
50       Exception types are considered to be hierarchical such that '"foo.bar"'
51       would be a specific type of the more general '"foo"' type.
52

METHODS

54   type()
55       Returns the exception type.
56
57   info()
58       Returns the exception information.
59

AUTHOR

61       Andy Wardley <abw@wardley.org> <http://wardley.org/>
62
64       Copyright (C) 1996-2022 Andy Wardley.  All Rights Reserved.
65
66       This module is free software; you can redistribute it and/or modify it
67       under the same terms as Perl itself.
68

SEE ALSO

70       Template, Template::Context
71
72
73
74perl v5.36.0                      2023-01-20            Template::Exception(3)
Impressum