The Exception module available on CPAN looks promising for this sort of thing.

In reply to Re: Idomatic Handling of Subroutine Error by dvergin
in thread Idomatic Handling of Subroutine Error by dvergin

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