You are on the right track...
Here what I do:
In my general DB writing routine:
eval {
... Lots of DB stuff with potential dies
};
if ( $@ ) { # if error
carp "DB error: $@";
return 0;
}
%changed = ( ... Some meaningful data ... );
return \%changed;
=======
In my Run modes
my $meaningful_Data_ref = DBroutine( \%pass_stuff_in );
unless ( $meaningful_Data_ref ) {
return error( $self, "Problem writing Dn Info to DB.", $@ ); }
======
the sub "error" handles writing the error message to the user in HTML (or whatever). Note that I still use $@ which is a "Global" indicator of the error message.
-----Original Message-----
From: Jason A. Crome [mailto:suppressed
Sent: Wednesday, August 11, 2004 10:11 AM
To: 'Peter Masiar'
Cc: suppressed
Subject: RE: [cgiapp] How do you handle errors?
I like the possibility of Mark's suggestion:
eval{ $result = _my_tricky_sub() };
return $self->error_runmode($@) if $@;
But it still doesn't quite help with the issue I'm having:
Consider my application, residing in Users.pm. It calls a function residing
in Receipting.pm called create_userid(). create_userid() currently should
return 1 if successful, else 0 (with the catch if there's a database error,
it would return the HTML for the error message). Receipting.pm is not
always called from a C::A, so I can't exactly get it to fire off another
runmode when a DB error occurs.
Would it be possible, for example, to create a package variable in
Receipting.pm that contains the last error message generated? If my DBI
call fails, set the package variable and return false. The calling C::A
then sees the error, it calls an error-handling runmode (which calls
log_error() and displays the resulting information for the user)? Or is
that all too hackish?
Any thoughts? Again, thanks! :)
--------------------------------------------------
Jason A. Crome
Senior Software Engineer, DEVNET, Inc.
E-Mail: suppressed
http://www.devnetinc.com
> -----Original Message-----
> From: Peter Masiar [mailto:suppressed
> Sent: Wednesday, August 11, 2004 11:44 AM
> To: Jason A. Crome
> Subject: Re: [cgiapp] How do you handle errors?
>
> Jason A. Crome wrote:
>
> > This probably covers more than just CGI::Application, but it's very
> > relevant to my current application, and I'm curious to see
> how others
> > have handled it.
>
> [big snip]
> > What have others done? What would you do in my place? I'm
> curious to
> > hear, because this is starting to drive me nuts ;)
>
> We have some info about error handling here:
> http://twiki.med.yale.edu/twiki2/bin/view/CGIapp/ErrorHandling
>
> When dust settles after this discussion, we would have more
> :-) Fell free to add it there (it's a wiki) - or I'll do that.
>
> I am curious to hear, too.
>
> --
> Peter Masiar, suppressed, NEW PHONE: (203)
> 737-2989 Yale Center for Medical Informatics (YCMI),
> http://ycmi.med.yale.edu I am not a lawyer. My ideas are NOT
> binding for University.
> In doubt, Yale policy right: http://www.yale.edu/policy/itaup.html
>
---------------------------------------------------------------------
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.