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 representing
22 exceptions within the template processing life cycle. Exceptions can
23 be raised by modules within the Template Toolkit, or can be generated
24 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 which can then be
42 handled in the usual way.
43
44 die "I'm sorry Dave, I can't do that";
45
46 Each exception is defined by its type and a information component (e.g.
47 error message). The type can be any identifying string and may contain
48 dotted components (e.g. 'foo', 'foo.bar', 'foo.bar.baz'). Exception
49 types are considered to be hierarchical such that 'foo.bar' would be a
50 specific type of the more general 'foo' type.
51
53 Andy Wardley <abw@wardley.org>
54
55 <http://wardley.org/⎪http://wardley.org/>
56
58 2.69, distributed as part of the Template Toolkit version 2.18,
59 released on 09 February 2007.
60
62 Copyright (C) 1996-2007 Andy Wardley. All Rights Reserved.
63
64 This module is free software; you can redistribute it and/or modify it
65 under the same terms as Perl itself.
66
68 Template, Template::Context
69
70
71
72perl v5.8.8 2007-02-09 Template::Exception(3)