Next: Text::Wigwam::Library::Filter | Previous: Text::Wigwam::Library::Datatype | [Table of Contents] | [Text::Wigwam Index] |
Text::Wigwam::Library::Debug #try, #catch, #caught, #throw, #warn
This library provides directives which are used for template debugging.
The directives within this library can be imported into specific branches of
the directive tree (which transcends from Text::Wigwam::Directives
) via
plug-ins or modules using one of the following techniques.
package Text::Wigwam::Directives::some::arbitrary::branch; # import everything use Text::Wigwam::Library::Debug( q/:all/ ); package Text::Wigwam::Directives::another::arbitrary::branch; # import selectively use Text::Wigwam::Library::Debug( qw/ :try :throw :catch :caught :warn / );
Traps any exceptions that may occur while executing block. This is useful
for error detection such as when using #div
or when executing child
templates. This directive is typically followed by the #catch
directive
which can be used to gracefully handle the exception.
[!! #try #div x y !!] [!! #catch { x " divided by " y " caused an error: " #caught } !!]
Only executes block if the #try
directive has trapped an exception
within the common block scope. Typically block should contain code designed
to handle the exception. The #caught
directive can be used to retrieve the
error from within block.
[!! #try #template "foo_primary" #catch { #try #template "foo_alternate" #catch { /* Report a custom error message */ #throw "Problem encountered while loading a required template" } } !!]
Generates an exception by setting the _DIE Global to message.
[!! #if no_hope #throw "I give up" !!]
This exception can be trapped using the #try
and #catch
directives.
Returns the error caught by the #try
directive from within a #caught
block.
[!! #try #throw "Bite it!" #catch { "D'oh! " #caught } /* output: D'oh! Error encountered in root template: Bite it! */ !!]
Alternatively, you can access the global directly via :caught.
[!! #try #throw "Bite me!" #catch { "D'oh! " :caught } /* output: D'oh! Error encountered in root template: Bite me! */ !!]
Stores comment for display in the template listing when compiled by the debugger.
Returns the error caught by the #try
directive from within a #caught
block.
[!! #try #throw "An explicitly forced exception" #catch { "An error occurred: " #error } /* output: An error occurred: An explicitly forced exception */ !!]