John Deighan wrote on 04/20/2005 08:25:09 AM:

> The problem with trying to use goto, or a return, or setting a global 
> variable is that they don't work well in a function that's being called 
by 
> the code that contains the eval. 'return' won't work because it will 
simply 
> return from the function that was called. I don't think that 'goto' will 

> work, though you might be able to goto <MODULE>::EOB, I don't know. The 
> global variable would still work, but I think that it requires too much 
> dependency between the module that the called function is in and the 
module 
> containing the eval. I was hoping for something that works just like 
die(), 
> but didn't set $@, but in the absence of that, I think that perhaps the 
> best solution is to do something like die("All is well\n"), then when 
> checking for $@ after the eval block, just treat that string as a 
special 
> case. Does anyone see a problem with that?
> 
> At 02:28 AM 4/20/2005, Anderson, Mark (Service Delivery) wrote:
> >perldoc -f goto
> >
> >eval {
> >         ...
> >         goto EOB;
> >         ...
> >         ...
> >         EOB: return;
> >};if($@){
> >         ...
> >}
> >
> >Kind regards,
> >
> >Mark Anderson
> >Service Improvement Programme
> >Level 2, 113 Dundas Street
> >Edinburgh, EH3 5DE
> >Tel: 0131 523 8786
> >Mob: 07808 826 063
> >
> >
> > > -----Original Message-----
> > > From: [EMAIL PROTECTED]
> > > [SMTP:[EMAIL PROTECTED] On Behalf 
Of John
> > > Deighan
> > > Sent: Tuesday, April 19, 2005 4:57 PM
> > > To:   perl-win32-users@listserv.ActiveState.com
> > > Subject:      die() without setting $@
> > >
> > > *** WARNING : This message originates from the Internet ***
> > >
> > > I need to be able to jump to the end of the enclosing eval block, 
just
> > > like
> > > a die() does, but without setting [EMAIL PROTECTED] Is there a way to do 
> > > that? 
(I've
> > > checked the Perl docs, but couldn't find it). I could possibly die() 
with
> > > a
> > > specific string, then use "if ($@ && ($@ ne <string>))" as the error 
trap,
> > >
> > > but that's aesthetically unpleasing.
> > >
> > > If you're interested in why, here's the explanation. Our web site is
> > > implemented via a series of "opcodes". The opcode is passed in the 
URL.
> > > There is a goto in our main script that dispatches to a particular 
opcode,
> > >
> > > and the code implementing the opcodes is surrounded by an eval 
block. When
> > >
> > > the output is generated, it's generated via a call to a library that
> > > outputs a page - usually using a template file. There is, however, 
also a
> > > function called errorPage() to which you pass a string. Now, when
> > > errorPage() is called, there has to be no further HTTP output, so 
I'd
> > > prefer, at the end of the errorPage() routine, to pass directly to 
the end
> > >
> > > of the eval block in the main code. die() does just that, but after 
the
> > > eval block, there's a "if ($@)" that handles any real errors, like
> > > database
> > > connection errors, direct calls to die(), etc., and I don't want 
calls to
> > > errorPage() to be treated like true errors (they're "user errors", 
which
> > > just means that we want to display a page to the user informing them 
of
> > > their error and how to correct it, and errorPage() does just that. 
Real
> > > errors result in us receiving an e-mail with the error message, and 
the
> > > error being logged to a database table).
> > >
Here's an off-the-cuff idea. But it may not meet your requirement to be 
aesthetically pleasing. At the point the eval block is to be exitted,
use die() with the current $@ encoded in the die string. Immediately
following the eval block, the die string would have to be decoded to
recover the $@ representing a "real error" and the rest of the die string
indicating "user error."


_______________________________________________
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to