You are viewing a plain text version of this content. The canonical link for it is here.
Posted to embperl@perl.apache.org by Robert Norris <Ro...@its.monash.edu.au> on 2005/02/17 01:07:29 UTC

[RESEND] Trapping errors

[Resend: I haven't recieved a reply, and I need to decide what to do
very soon.]

Hi all,

I'm working with Embperl 2.0rc2, using Embperl::Object for the entire
site. I've having some issues with error trapping, and I've been unable
to figure it out by myself, so I seek your advice.

My understanding so far is that compile errors will always cause a 500
error, and so can only be handled with an appropriate ErrorDocument.
Runtime errors, on the other hand, can be handled by my own code (ie
from base.epl).

My usual way of handling errors (ie outside of Embperl) is via a custom
class that contains all the bits I need. When I get an error, I
instantiate this class and then call Carp::croak, eg:

  my $dbh = DBI->connect(...)
  croak(internal::error->new(type => 'db', action => 'retry',
                             text => 'DB connect failed')) if not $dbh;

Then I run stuff inside eval blocks. If I get an error, I test $@ with
UNIVERSAL::isa. If its my class, I handle it one way, if not (ie its a
Perl or 3rd-party module error), I handle it another.

The first thing I did was to port this to Embperl. Rather than calling
internal::error->new, I do:

  my $err = Execute({object => 'util/error.epl'});
  ...
  croak($err->new(...));

And then in base.epl, something like this:

  eval { Execute('*') };
  if($@) {
      Execute('error.epl', $@);
  }

This seemed to work, so I left it there and continued on the rest of the
site. I've since found that it doesn't work all the time, for reasons
that I can't explain (my reading of Embperl::Object::Execute suggests
that it should never work, so I don't know).

On the times it doesn't work, I get the standard Embperl error page.

I've had a look through the mailing lists, and information is sketchy,
but it was there I found out about the "errors" argument to Execute.
I've tried that, but I never get anything returned to me in the error
array.

I've set optReturnError, which isn't making a difference. I get the
error reported in the server log, but nothing else (not even a 500 error
from Apache, interestingly enough).

So where do I go from here? Is there a single way to trap all runtime
errors (Embperl + croak/die)? What distinguishes an Embperl error (ie
something that would be returned in the error array) from any other
error?

Thanks,
Rob.

--
Robert Norris                          <Ro...@its.monash.edu.au>
Messaging & Scheduling Group             Information Technology Services

Re: [RESEND] Trapping errors

Posted by Robert Norris <Ro...@its.monash.edu.au>.
On Wed, Feb 23, 2005 at 05:28:17AM +0100, Gerald Richter wrote:
> > Any way to make this behave more like croak/die? These seem to check if
> > their argument is a reference. If it is, they just drop the reference
> > into $@, otherwise they add context (line number, etc).
> >
> 
> I take a look at it if I can change the error handling in this way.
> 
> I agree that this would make sense
> 
> Just give me a few days

Awesome. Thanks for you efforts!

Rob.

Re: [RESEND] Trapping errors

Posted by Gerald Richter <ri...@ecos.de>.
Hi,

>
> Any way to make this behave more like croak/die? These seem to check if
> their argument is a reference. If it is, they just drop the reference
> into $@, otherwise they add context (line number, etc).
>

I take a look at it if I can change the error handling in this way.

I agree that this would make sense

Just give me a few days

Gerald


---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
For additional commands, e-mail: embperl-help@perl.apache.org


Re: [RESEND] Trapping errors

Posted by Robert Norris <Ro...@its.monash.edu.au>.
Hi Gerald,

Thanks for your reply.

On Tue, Feb 22, 2005 at 05:52:33PM +0100, Gerald Richter wrote:
> > And then in base.epl, something like this:
> >
> >   eval { Execute('*') };
> >   if($@) {
> >       Execute('error.epl', $@);
> >   }
> >
> 
> Instead use
> 
> Execute({inputfile => '*', options => Embperl::Constant::optReturnError, 
> errors => \@errors}) ;
> if (@errors) {
> 	Execute (....
> }

This is almost working. The only problem I have now is that I'm throwing
and object reference (containing all sorts of info about the error).
Embperl seems to be stringifying it before dropping it into @errors, so
I get:

  [23835]ERR: 24: Error in Perl code: Util::Error=HASH(0x84f76f0)

Any way to make this behave more like croak/die? These seem to check if
their argument is a reference. If it is, they just drop the reference
into $@, otherwise they add context (line number, etc).

Thanks,
Rob.

RE: [RESEND] Trapping errors

Posted by Gerald Richter <ri...@ecos.de>.
> 
> > Instead use
> > 
> > Execute({inputfile => '*', options =>
> > Embperl::Constant::optReturnError,
> > errors => \@errors}) ;
> > if (@errors) {
> > 	Execute (....
> > }
> > 
> 
> I've been doing something recently with Execute and
> @errors, and I noticed that the @errors array also
> contained any 'warnings' as well as errors... 
> 
> I came across a previous post of yours, Gerald, which
> said that the the way to check if errors have occured
> would be to check the return value of the Execute....
> So if the Embperl script only contained warnings you
> could tell the difference...
> 
> Is this still the case?
> 

Yes, that's still true

Gerald


---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
For additional commands, e-mail: embperl-help@perl.apache.org


Re: [RESEND] Trapping errors

Posted by Martin Moss <ma...@btopenworld.com>.
> Instead use
> 
> Execute({inputfile => '*', options =>
> Embperl::Constant::optReturnError, 
> errors => \@errors}) ;
> if (@errors) {
> 	Execute (....
> }
> 

I've been doing something recently with Execute and
@errors, and I noticed that the @errors array also
contained any 'warnings' as well as errors... 

I came across a previous post of yours, Gerald, which
said that the the way to check if errors have occured
would be to check the return value of the Execute....
So if the Embperl script only contained warnings you
could tell the difference...

Is this still the case?

kind regards

Marty





	
	
		
___________________________________________________________ 
ALL-NEW Yahoo! Messenger - all new features - even more fun! http://uk.messenger.yahoo.com

---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
For additional commands, e-mail: embperl-help@perl.apache.org


Re: [RESEND] Trapping errors

Posted by Gerald Richter <ri...@ecos.de>.
>
> And then in base.epl, something like this:
>
>   eval { Execute('*') };
>   if($@) {
>       Execute('error.epl', $@);
>   }
>

Instead use

Execute({inputfile => '*', options => Embperl::Constant::optReturnError, 
errors => \@errors}) ;
if (@errors) {
	Execute (....
}


Gerald




---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
For additional commands, e-mail: embperl-help@perl.apache.org