3
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Strict//EN">
6
<title>Template::Exception</title>
7
<link rel="stylesheet" type="text/css" href="../../css/blue.css" title="Clear Blue">
8
<link rel="alternate stylesheet" type="text/css" href="../../css/orange.css" title="Clear Orange">
9
<link rel="alternate stylesheet" type="text/css" href="../../css/green.css" title="Clear Green">
10
<link rel="alternate stylesheet" type="text/css" href="../../css/purple.css" title="Clear Purple">
11
<link rel="alternate stylesheet" type="text/css" href="../../css/grey.css" title="Clear Grey">
13
<link rel="stylesheet" type="text/css" href="../../css/ie6.css" />
15
<link rel="stylesheet" type="text/css" href="/css/print.css" media="print">
16
<script type="text/javascript" src="../../js/tt2.js"></script>
17
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
18
<meta name="author" content="Andy Wardley">
23
<a href="../../index.html" id="logo" alt="" title="Click for the Home Page"><span class="alt">TT2 Home Page</span></a>
25
<li><a href="../../modules/index.html">Modules</a></li>
26
<li><a href="../../modules/Template/index.html">Template::*</a></li>
27
<li class="last"><a href="../../modules/Template/Exception.html">Exception.pm</a></li>
29
<div class="controls">
30
<a href="#" class="menu show" onclick="widescreen_off(); return false" title="Show Menu">
31
<span class="about">Click to view the menu. It's very nice.</span>
33
<a href="#" class="menu hide" onclick="widescreen_on(); return false" title="Hide Menu">
34
<span class="about">Click to hide the menu and go all widescreen!</span>
38
<a href="../../modules/Template/Document.html" title="Template::Document" class="go back">Back<span class="about"><h4>Template::Document</h4>Compiled template document object</span></a>
39
<a href="../../modules/Template/index.html" title="Template::* Modules" class="go up">Up<span class="about"><h4>Template::* Modules</h4></span></a>
40
<a href="../../modules/Template/Filters.html" title="Template::Filters" class="go next">Next<span class="about"><h4>Template::Filters</h4>Post-processing filters for template blocks</span></a>
43
<h1 class="headline">Template::Exception</h1>
44
<h2 class="subhead">Exception handling class module</h1>
49
<a href="../../index.html" id="logo"></a>
52
<li class="l0 first"><a href="../../manual/index.html">Manual</a></li>
53
<li class="l0"><a href="../../modules/index.html" class="warm">Modules</a></li>
54
<li class="l1"><a href="../../modules/Template.html">Template.pm</a></li>
55
<li class="l1"><a href="../../modules/Template/index.html" class="warm">Template::*</a></li>
56
<li class="l2"><a href="../../modules/Template/Base.html">Base.pm</a></li>
57
<li class="l2"><a href="../../modules/Template/Config.html">Config.pm</a></li>
58
<li class="l2"><a href="../../modules/Template/Constants.html">Constants.pm</a></li>
59
<li class="l2"><a href="../../modules/Template/Context.html">Context.pm</a></li>
60
<li class="l2"><a href="../../modules/Template/Directive.html">Directive.pm</a></li>
61
<li class="l2"><a href="../../modules/Template/Document.html">Document.pm</a></li>
62
<li class="l2"><a href="../../modules/Template/Exception.html" class="warm">Exception.pm</a></li>
63
<li class="l2"><a href="../../modules/Template/Filters.html">Filters.pm</a></li>
64
<li class="l2"><a href="../../modules/Template/Grammar.html">Grammar.pm</a></li>
65
<li class="l2"><a href="../../modules/Template/Iterator.html">Iterator.pm</a></li>
66
<li class="l2"><a href="../../modules/Template/Namespace/index.html">Namespace::*</a></li>
67
<li class="l2"><a href="../../modules/Template/Parser.html">Parser.pm</a></li>
68
<li class="l2"><a href="../../modules/Template/Plugin.html">Plugin.pm</a></li>
69
<li class="l2"><a href="../../modules/Template/Plugin/index.html">Plugin::*</a></li>
70
<li class="l2"><a href="../../modules/Template/Plugins.html">Plugins.pm</a></li>
71
<li class="l2"><a href="../../modules/Template/Provider.html">Provider.pm</a></li>
72
<li class="l2"><a href="../../modules/Template/Service.html">Service.pm</a></li>
73
<li class="l2"><a href="../../modules/Template/Stash.html">Stash.pm</a></li>
74
<li class="l2"><a href="../../modules/Template/Stash/index.html">Stash::*</a></li>
75
<li class="l2"><a href="../../modules/Template/Test.html">Test.pm</a></li>
76
<li class="l2"><a href="../../modules/Template/VMethods.html">VMethods.pm</a></li>
77
<li class="l2"><a href="../../modules/Template/View.html">View.pm</a></li>
78
<li class="l0"><a href="../../tools/index.html">Tools</a></li>
79
<li class="l0 last"><a href="../../tutorial/index.html">Tutorial</a></li>
81
<div class="foot"></div>
87
<h1 id="contents" onclick="switch_section(this)" title="Click title to show/hide section content.">Contents</h1>
88
<a href="#body" class="top" title="Back up to the top of the page" >Top</a>
92
<li class=""><a href="#SYNOPSIS">SYNOPSIS</a></li>
93
<li class=""><a href="#DESCRIPTION">DESCRIPTION</a></li>
94
<li class=""><a href="#METHODS">METHODS</a></li>
95
<li class="sub"><a href="#method_type">type()</a></li>
96
<li class="sub"><a href="#method_info">info()</a></li>
97
<li class=""><a href="#AUTHOR">AUTHOR</a></li>
98
<li class=""><a href="#COPYRIGHT">COPYRIGHT</a></li>
99
<li class=""><a href="#SEE_ALSO">SEE ALSO</a></li>
106
<div class="section">
108
<h1 id="SYNOPSIS" onclick="switch_section(this)" title="Click title to show/hide section content.">SYNOPSIS</h1>
109
<a href="#body" class="top" title="Back up to the top of the page" >Top</a>
112
<pre>use Template::Exception;
114
my $exception = Template::Exception->new($type, $info);
115
$type = $exception->type;
116
$info = $exception->info;
117
($type, $info) = $exception->type_info;
119
print $exception->as_string();
121
$handler = $exception->select_handler(\@candidates);</pre>
124
<div class="section">
126
<h1 id="DESCRIPTION" onclick="switch_section(this)" title="Click title to show/hide section content.">DESCRIPTION</h1>
127
<a href="#body" class="top" title="Back up to the top of the page" >Top</a>
131
The <code>Template::Exception</code> module defines an object class for
132
representing exceptions within the template processing life cycle.
133
Exceptions can be raised by modules within the Template Toolkit, or can
134
be generated and returned by user code bound to template variables.
137
Exceptions can be raised in a template using the <code>THROW</code>
140
<pre>[% THROW user.login 'no user id: please login' %]</pre>
142
or by calling the <a href="../../modules/Template/Context.html#method_throw">throw()</a> method on the current <a href="../../modules/Template/Context.html">Template::Context</a> object,
144
<pre>$context->throw('user.passwd', 'Incorrect Password');
145
$context->throw('Incorrect Password'); # type 'undef'</pre>
147
or from Perl code by calling <code>die()</code> with a
148
<code>Template::Exception</code> object,
150
<pre>die (Template::Exception->new('user.denied', 'Invalid User ID'));</pre>
152
or by simply calling <code>die()</code> with an error string. This is
153
automagically caught and converted to an exception of
154
'<code>undef</code>' type (that's the literal string '<code>undef</code>'
155
rather than Perl's undefined value) which can then be handled in the
158
<pre>die "I'm sorry Dave, I can't do that";</pre>
160
Each exception is defined by its type and a information component (e.g.
161
error message). The type can be any identifying string and may contain
162
dotted components (e.g. '<code>foo</code>', '<code>foo.bar</code>',
163
'<code>foo.bar.baz</code>'). Exception types are considered to be
164
hierarchical such that '<code>foo.bar</code>' would be a specific type of
165
the more general '<code>foo</code>' type.
169
<div class="section">
171
<h1 id="METHODS" onclick="switch_section(this)" title="Click title to show/hide section content.">METHODS</h1>
172
<a href="#body" class="top" title="Back up to the top of the page" >Top</a>
175
<div class="subsection">
177
<h2 id="method_type" class="method" onclick="switch_subsection(this)" title="Click title to show/hide sub-section content.">type()</h2>
178
<a href="#body" class="top" title="Back up to the top of the page" >Top</a>
182
Returns the exception type.
185
</div> <div class="subsection">
187
<h2 id="method_info" class="method" onclick="switch_subsection(this)" title="Click title to show/hide sub-section content.">info()</h2>
188
<a href="#body" class="top" title="Back up to the top of the page" >Top</a>
192
Returns the exception information.
198
<div class="section">
200
<h1 id="AUTHOR" onclick="switch_section(this)" title="Click title to show/hide section content.">AUTHOR</h1>
201
<a href="#body" class="top" title="Back up to the top of the page" >Top</a>
205
Andy Wardley <abw@wardley.org> <a
206
href="http://wardley.org/">http://wardley.org/</a>
210
<div class="section">
212
<h1 id="COPYRIGHT" onclick="switch_section(this)" title="Click title to show/hide section content.">COPYRIGHT</h1>
213
<a href="#body" class="top" title="Back up to the top of the page" >Top</a>
217
Copyright (C) 1996-2007 Andy Wardley. All Rights Reserved.
220
This module is free software; you can redistribute it and/or modify it
221
under the same terms as Perl itself.
225
<div class="section">
227
<h1 id="SEE_ALSO" onclick="switch_section(this)" title="Click title to show/hide section content.">SEE ALSO</h1>
228
<a href="#body" class="top" title="Back up to the top of the page" >Top</a>
232
<a href="../../modules/Template.html">Template</a>, <a href="../../modules/Template/Context.html">Template::Context</a>
239
<div class="pageinfo">
240
/modules/Template/Exception.html last modified 10:57:47 31-May-2007
245
<a href="http://opensource.org/" class="osi"></a>
246
<div class="controls">
248
<a href="../../modules/Template/Document.html" title="Template::Document" class="go back">Back<span class="about"><h4>Template::Document</h4></span></a>
249
<a href="../../modules/Template/index.html" title="Template::* Modules" class="go up">Up<span class="about"><h4>Template::* Modules</h4></span></a>
250
<a href="../../modules/Template/Filters.html" title="Template::Filters" class="go next">Next<span class="about"><h4>Template::Filters</h4></span></a>
253
<div class="copyright">
254
Copyright © 1996-2007 <a href="http://wardley.org/">Andy Wardley</a>. All Rights Reserved.
256
<div class="licence">
257
The <a href="http://template-toolkit.org/">Template Toolkit</a> is <a href="http://opensource.org/">Open Source</a> software.
258
You can redistribute and/or modify it under the terms of the <a href="http://www.opensource.org/licenses/gpl-license.php">GNU Public Licence</a>
259
or the <a href="http://www.opensource.org/licenses/artistic-license.php">Perl Artistic Licence</a>.
264
<li class="first"><a href="#" class="blue" onclick="set_style('Clear Blue')"></a></li>
265
<li><a href="#" class="orange" onclick="set_style('Clear Orange')"></a></li>
266
<li><a href="#" class="green" onclick="set_style('Clear Green')"></a></li>
267
<li><a href="#" class="purple" onclick="set_style('Clear Purple')"></a></li>
268
<li><a href="#" class="grey" onclick="set_style('Clear Grey')"></a></li>