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


In reply to Re: Mason error capturing by martell
in thread Mason error capturing by inblosam

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.