1HTML::Mason::ExceptionsU(s3e)r Contributed Perl DocumentaHtTiMoLn::Mason::Exceptions(3)
2
3
4

NAME

6       HTML::Mason::Exceptions - Exception objects thrown by Mason
7

SYNOPSIS

9         use HTML::Mason::Exceptions ( abbr => [ qw(system_error) ] );
10
11         open FH, 'foo' or system_error "cannot open foo: $!";
12

DESCRIPTION

14       This module creates the hierarchy of exception objects used by Mason,
15       and provides some extra methods for them beyond those provided by
16       "Exception::Class"
17

IMPORT

19       When this module is imported, it is possible to specify a list of
20       abbreviated function names that you want to use to throw exceptions.
21       In the SYNOPSIS example, we use the "system_error" function to throw a
22       "HTML::Mason::Exception::System" exception.
23
24       These abbreviated functions do not allow you to set additional fields
25       in the exception, only the message.
26

EXCEPTIONS

28       HTML::Mason::Exception
29           This is the parent class for all exceptions thrown by Mason.  Mason
30           sometimes throws exceptions in this class when we could not find a
31           better category for the message.
32
33           Abbreviated as "error"
34
35       HTML::Mason::Exception::Abort
36           The "$m->abort" method was called.
37
38           Exceptions in this class contain the field "aborted_value".
39
40       HTML::Mason::Exception::Decline
41           The "$m->decline" method was called.
42
43           Exceptions in this class contain the field "declined_value".
44
45       HTML::Mason::Exception::Compilation
46           An exception occurred when attempting to "eval" an existing object
47           file.
48
49           Exceptions in this class have the field "filename", which indicates
50           what file contained the code that caused the error.
51
52           Abbreviated as "compilation_error".
53
54       HTML::Mason::Exception::Compiler
55           The compiler threw an exception because it received incorrect
56           input.  For example, this would be thrown if the lexer told the
57           compiler to initialize compilation while it was in the middle of
58           compiling another component.
59
60           Abbreviated as "compiler_error".
61
62       HTML::Mason::Exception::Compilation::IncompatibleCompiler
63           A component was compiled by a compiler or lexer with incompatible
64           options.  This is used to tell Mason to recompile a component.
65
66           Abbreviated as "wrong_compiler_error".
67
68       HTML::Mason::Exception::Params
69           Invalid parameters were passed to a method or function.
70
71           Abbreviated as "param_error".
72
73       HTML::Mason::Exception::Syntax
74           This exception indicates that a component contained invalid syntax.
75
76           Exceptions in this class have the fields "source_line", which is
77           the actual source where the error was found, "comp_name", and
78           "line_number".
79
80           Abbreviated as "syntax_error".
81
82       HTML::Mason::Exception::System
83           A system call of some sort, such as a file open, failed.
84
85           Abbreviated as "system_error".
86
87       HTML::Mason::Exception::TopLevelNotFound
88           The requested top level component could not be found.
89
90           Abbreviated as "top_level_not_found_error".
91
92       HTML::Mason::VirtualMethod
93           Some piece of code attempted to call a virtual method which was not
94           overridden.
95
96           Abbreviated as "virtual_error"
97

FIELDS

99       Some of the exceptions mentioned above have additional fields, which
100       are available via accessors.  For example, to get the line number of an
101       "HTML::Mason::Exception::Syntax" exception, you call the "line_number"
102       method on the exception object.
103

EXCEPTION METHODS

105       All of the Mason exceptions implement the following methods:
106
107       as_brief
108           This simply returns the exception message, without any trace
109           information.
110
111       as_line
112           This returns the exception message and its trace information, all
113           on a single line with tabs between the message and each frame of
114           the stack trace.
115
116       as_text
117           This returns the exception message and stack information, with each
118           frame on a separate line.
119
120       as_html
121           This returns the exception message and stack as an HTML page.
122
123       Each of these methods corresponds to a valid error_format parameter for
124       the Request object such as "text" or "html".
125
126       You can create your own method in the "HTML::Mason::Exception"
127       namespace, such as "as_you_wish", in which case you could set this
128       parameter to "you_wish".  This method will receive a single argument,
129       the exception object, and is expected to return some sort of string
130       containing the formatted error message.
131

EXCEPTION CLASS CHECKING

133       This module also exports the "isa_mason_exception" function.  This
134       function takes the exception object and an optional string parameter
135       indicating what subclass to check for.
136
137       So it can be called either as:
138
139         if ( isa_mason_exception($@) ) { ... }
140
141       or
142
143         if ( isa_mason_exception($@, 'Syntax') ) { ... }
144
145       Note that when specifying a subclass you should not include the leading
146       "HTML::Mason::Exception::" portion of the class name.
147
148
149
150perl v5.38.0                      2023-07-20        HTML::Mason::Exceptions(3)
Impressum