Hi,
I'm also using HTML::Mason for development. To solve this problem I left the error handling at output and I created a special module that writes a custom error to the user when an error occurs.
Mason uses the standard Exception::Class module to handle errors. If an error thrown is a string, it will convert it to a 'HTML::Mason::Exception' otherwise it will rethrow it.(cfr here)
This means that you can catch the errors and handle like you do in regular code.
So in my mason files I put now:
<%init>
eval {
#code that can throw errors
};
if ($debug and ( UNIVERSAL::isa( $@,'HTML::Mason::Exception' )) { #
+ let all Mason errors pass like usual if in debug mode
$@->rethrow;
}
elsif ($@) { # catch all errors
#stringify the error and call an error component
$m->comp('error.mhtml', 'text' => "$@");
}
</%init>
#HTML code
The "$@" takes care of showing the error by stringifying it. The error module does some additional tasks like destroying the session, format the error, ... It could be expanded with error writing although.
The $debug variable is a global one specified in the apache config file and takes the role as switch to activate the mason error handling. (Remark, in this case, all none mason errors will always be treated by the error component.)
It was for me the simplest way of doing this. But I admit it is maybe not the standard mason way to do it. I had to add this code in all my mason components. This is not big problem because I have only a limited number of components that can expect errors, but it could be a bit tendious to do.
So I advice you to post your question on the mason-users list on www.masonhq.com. The people over there are most kindly to help you.
regards
martell
|