Dear monk,

I am using CGI::Application and find it quite useful, but sometimes I have the feeling that I must be too stupid to properly use it as what I do just looks silly to me, yet I cannot find a better solution - which is why I hope for some enlightenment here.

One of my problems is exception-handling in cgi_prerun.

Assume I have a error-runmode configured that gets called whenever an exception occurs in a normal runmode. Very handy.

But now I also have a cgiapp_prerun method that handles some generic stuff that also may throw an exception.

Unfortunately CGI::App does not do exception handling for you in the prerun so you have to catch any possible exception yourself and the question is now how to transfer control to the error-runmode and how to pass the exception on.

Calling the error-runmode directly does not work so my workaround looks something like this (I am also using CGI::Application::Plugin::Stash):

sub cgiapp_prerun { my($this, $rm)=@_; eval { ... }; if($@) { $this->stash->{exception} = $@; $this->prerun_mode("prerun_error") } } sub prerun_error { my($this)=@_; $this->error($this->stash->{exception}); } sub error { # error-runmode my($this, $exception)=@_; ... }
This works but it looks ridiculous...

I pass the exception via the stash (basically creating a global variable) and need the prerun_error runmode only to pass control on the error-runmode, because the only way out from cgiapp_prerun seems to be via prerun_mode How would you do this?

Many thanks!


In reply to CGI::Application cgi_prerun exception handling by morgon

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.