Brian McCauley [EMAIL PROTECTED] wrote:
> [EMAIL PROTECTED] (Dataondata) writes:
> 
> > I am using the following code and would like someway to display errors and/or 
> > redirect on event of crash
> > inside the IF block at about where the #ERROR COULD BE HERE point:
> 
> Your question has nothing to do with DBI - I suggest you try a general
> Perl formum.
> 
> But before you post there lurk for a while.  Your code illustrates
> many bad habits of the sort that make your code less reliable and are
> always under discussion in the Perl fora.
> 
>   Failure to delare variables in correct lexical scope.
>   Failure to enable strict/warnings to help Perl to help you.
>   Relative path in CGI script (doesn't work on all HTTPDs).
>   Using .cgi suffix for a perl4 style library (obfuscation).
>   Using Perl4 style libraries in CGI scripts (doen't play nice with
>   mod_perl).
>   Useless use of BEGIN {}
>   Useless use of & in subroutine calls.
> 
> BTW the error trapping mechanism in Perl is eval{}.
> 
> For details:
> 
>   perldoc -f eval
> 
> But DBI does not thow Perl errors as a result of database errors
> unless you tell it to.  If you don't tell it you have to explicitly
> check for errors after each operation.
> 
> For details:
> 
>   perldoc DBI

Besides Brian's good comments, I'll just clarify that you need
to test/trap errors on *all* your DBI statements, including the
connect and prepare.  Read the whole 'perldoc DBI', and pay
particular attention to the section on "RaiseError" and
"Transactions", and as Brian said "eval".

HTH.
-- 
Hardy Merrill
Red Hat, Inc.

Reply via email to