HTML::Mason::Exceptions(3pm) | User Contributed Perl Documentation | HTML::Mason::Exceptions(3pm) |
HTML::Mason::Exceptions - Exception objects thrown by Mason
use HTML::Mason::Exceptions ( abbr => [ qw(system_error) ] ); open FH, 'foo' or system_error "cannot open foo: $!";
This module creates the hierarchy of exception objects used by Mason, and provides some extra methods for them beyond those provided by "Exception::Class"
When this module is imported, it is possible to specify a list of abbreviated function names that you want to use to throw exceptions. In the SYNOPSIS example, we use the "system_error" function to throw a "HTML::Mason::Exception::System" exception.
These abbreviated functions do not allow you to set additional fields in the exception, only the message.
Abbreviated as "error"
Exceptions in this class contain the field "aborted_value".
Exceptions in this class contain the field "declined_value".
Exceptions in this class have the field "filename", which indicates what file contained the code that caused the error.
Abbreviated as "compilation_error".
Abbreviated as "compiler_error".
Abbreviated as "wrong_compiler_error".
Abbreviated as "param_error".
Exceptions in this class have the fields "source_line", which is the actual source where the error was found, "comp_name", and "line_number".
Abbreviated as "syntax_error".
Abbreviated as "system_error".
Abbreviated as "top_level_not_found_error".
Abbreviated as "virtual_error"
Some of the exceptions mentioned above have additional fields, which are available via accessors. For example, to get the line number of an "HTML::Mason::Exception::Syntax" exception, you call the "line_number" method on the exception object.
All of the Mason exceptions implement the following methods:
Each of these methods corresponds to a valid error_format parameter for the Request object such as "text" or "html".
You can create your own method in the "HTML::Mason::Exception" namespace, such as "as_you_wish", in which case you could set this parameter to "you_wish". This method will receive a single argument, the exception object, and is expected to return some sort of string containing the formatted error message.
This module also exports the "isa_mason_exception" function. This function takes the exception object and an optional string parameter indicating what subclass to check for.
So it can be called either as:
if ( isa_mason_exception($@) ) { ... }
or
if ( isa_mason_exception($@, 'Syntax') ) { ... }
Note that when specifying a subclass you should not include the leading "HTML::Mason::Exception::" portion of the class name.
2022-10-13 | perl v5.34.0 |