Solution 1.
We could simply remove the catch/rethrow altogether, and leave it up to
Perl to say that the method can't be dispatched if that's the case:


Solution 2. Slightly nicer than that: Pick off those cases where the run mode method dispatch might fail and use the catch/rethrow to give a nice error in those cases. Don't use it otherwise.

Solution 3.

Retain the exception catching in all circumstances, but provide (yet
another) overridable method, cgiapp_exception(), to deal with the
exception that we've just caught. The default implementation of the new
method would, of course, be the current behaviour.


Which solution do you prefer? What other solutions are there?

I like solution 1 over solution 2.


Solution 2 has the same problems as the current implementation in that it treats exceptions returned from auto-loaded methods as strings.
I never thought of auto-loading in the first place, but if we are to support it, we should do it properly (including allowing it to die with exceptions).


I see your problem with solution 3, in that cgiapp_exception adds an additional stack frame if it dies.
However, cgiapp_exception does not necessarily have to die at all.
It could just produce a nice error page, and then return to let run() finish its work (headers, teardown and all)
What I am currently doing is an extended version of solution 3.


Solution 4

cgiapp_exception is allowed to return a result, which is then sent to the client (instead of the normal runmode output).

# Process run mode!
my $body = eval { $autoload_mode ? $self->$rmeth($rm) :
$self->$rmeth() };
- die "Error executing run mode '$rm': $@" if $@;
+ if ($@) {
+ $body = $self->cgiapp_exception($rm, $@); # in case cgiapp_exception does not die
+ }


We could solve the stack frame thing by not having cgiapp_exception defined in the base class,
and only calling it "if we can()" (because it has been defined in subclasses).
If it is not defined, we just die as in solution 1


     # Process run mode!
     my $body = eval { $autoload_mode ? $self->$rmeth($rm) :
$self->$rmeth() };
-    die "Error executing run mode '$rm': $@" if $@;
+    if ($@) {
+       if ($self->can('cgiapp_exception'){
+               $body = $self->cgiapp_exception($rm, $@);
+       }
+       else{
+               die $@;
+       }
+    }



Thilo






--------------------------------------------------------------------- Web Archive: http://www.mail-archive.com/[EMAIL PROTECTED]/ http://marc.theaimsgroup.com/?l=cgiapp&r=1&w=2 To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to