[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: [cgiapp] RE: Changing run modes from another run mode


The problem is intractable with Perl5's syntax. You'll have to wait
until the first Perl is built upon Parrot, which will provide that kind
of try-catch syntax.

Better is to just use the following:

eval {
    # Code that may die
}; if ($@) {
}

You will have to create your own rethrow syntax by determining exactly
what $@ contains and use die yourself. Now, $@ can be an object as well,
as long as it's the only thing passed to die. This can be useful, I
s'pose.

Rob

-----Original Message-----
From: Stephen Howard [mailto:suppressed 
Sent: Friday, March 26, 2004 4:58 PM
To: suppressed
Subject: Re: [cgiapp] RE: Changing run modes from another run mode

oh, well that's good to know.  Do you know of another module out there 
that implements similar semantics without Error.pm's issues?

Kinyon, Rob wrote:

> Error.pm has an intractable memory leak issue regarding closures. I
> would strongly recommend not using this module unless you can
guarantee
> you do not generate any closures within the try block.
> 
> -----Original Message-----
> From: Stephen Howard [mailto:suppressed 
> Sent: Wednesday, March 24, 2004 10:57 AM
> To: suppressed
> Subject: Re: [cgiapp] RE: Changing run modes from another run mode
> 
> Something else you might consider is using the excellent Error.pm
module
> 
> from CPAN. Then you can do something like this (using rob's subroutine

> identifiers):
> 
> sub A {
> 
>   try {
>       sub B()
>   }
>   catch Error with {
>       return sub C()
>   }
> 
> }
> 
> sub B {
> 
>     throw Error('error string') if $bad_condition
> }
> 
> Error.pm was designed with propagating errors up the call stack in
mind,
> 
> so that they can be handled gracefully at the appropriate level.
> 
> Kinyon, Rob wrote:
> 
> 
>>Basically, it sounds like your problem boils down to this:
>>1) You are in runmode A.
>>2) You call function B.
>>3) Within function B, you determine you have error condition C.
>>4) You now need to switch from runmode A to runmode C.
>>
>>The issue you're running into is the function stack. You have called
>>function B from within function A. You want to change the stack frame
>>for function A into the stack frame for function C. Not so simple.
>>
>>There are a few ways to go about this, some more complicated than
>>others. The easiest one, in my opinion, is to return from function B
> 
> two
> 
>>values - one that indicates an error has occurred and the other
>>indicating what runmode to call now. Something like:
>>
>>   my ($error, $runmode) = functionB(@parameters);
>>   return $self->$runmode if $error;
>>
>>This method requires runmode A to know that functionB might have
> 
> errors.
> 
>>It doesn't require runmode A to know that -this- error goes to -that-
>>runmode. 
>>
>>The other solutions tend to be a little more ... complex. I'd try that
>>one first.
>>
>>Rob
>>
>>-----Original Message-----
>>From: suppressed [mailto:suppressed 
>>Sent: Tuesday, March 23, 2004 6:48 PM
>>To: suppressed
>>Subject: Changing run modes from another run mode
>>
>>I have what looks like a fairly simple problem. I have a run mode and 
>>this run mode calls a utility method. The utility method might throw
an
> 
> 
>>error, but the error is fixable. I want my utility method to see if it
>>has an 
>>error and then switch to a specific error run mode to fix the error.
> 
> The
> 
>>problem is, of course, I can't switch run modes from my utility
method,
> 
> 
>>the only place I can switch is from the cgiapp_prerun method. Whats 
>>the best way to hack around this problem?
>>
>>---------------------------------------------------------------------
>>Web Archive:  http://www.mail-archive.com/suppressed/
>>             http://marc.theaimsgroup.com/?l=cgiapp&r=1&w=2
>>To unsubscribe, e-mail: suppressed
>>For additional commands, e-mail: suppressed
>>
>>
>> 
>>
> 
> 
> 
> ---------------------------------------------------------------------
> Web Archive:  http://www.mail-archive.com/suppressed/
>               http://marc.theaimsgroup.com/?l=cgiapp&r=1&w=2
> To unsubscribe, e-mail: suppressed
> For additional commands, e-mail: suppressed
> 
> 

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


Mail converted by mhonarc 2.6.15
This archive provided courtesy of JSW4.NET, Internet Hosting Services for Small Business.