Thanks for all of the feedback.  I realize that using the eval{} statement
is probably the way to go.  However, as I am new to this, I don't quite "get
it" yet.  Since this is going to be on a relatively low-traffic intranet
site behind a firewall, I used a MySQL query in a subroutine before the
insert subroutine is called.  If it finds the submitted e-mail in the
database, it prints a nice error message that I created to the browser and
the script stops.

Thanks for all of your feedback.  I actually bought Perl DBI yesterday, so
hopefully, I will soon grasp a better understanding of the DBI module.

Thanks,
Andrew

-----Original Message-----
From: Steve Haslam [mailto:[EMAIL PROTECTED]]
Sent: Monday, January 20, 2003 12:31 PM
To: 'Hughes, Andrew'; '[EMAIL PROTECTED]'
Subject: RE: Error Handling


> entered into the database.  With this code, I recieve the Carp error in
the
> browser.  When I turn off Carp, the script acts as if the entry was added
> (no error displayed), but the record is not entered.  Can anyone offer
> suggestions on how to make decisions based on a DBI error message ?

wrap your $dbh->do() in an eval block:

eval {
 $dbh->do( ... insert statement ... );
};
if ($@ =~ /constraint violation/) # or whatever the error message is
{
  return &duplicate_email();
}
elsif ($@) # some other error occurred
{
  die $@;
}
# insert succeeded...


Please note that:
 
1. This e-mail may constitute privileged information. If you are not the
intended recipient, you have received this confidential email and any
attachments transmitted with it in error and you must not disclose, copy,
circulate or in any other way use or rely on this information.
2. E-mails to and from the company are monitored for operational reasons and
in accordance with lawful business practices.
3. The contents of this email are those of the individual and do not
necessarily represent the views of the company.
4. The company does not conclude contracts by email and all negotiations are
subject to contract.
5. The company accepts no responsibility once an e-mail and any attachments
is sent.

http://www.activis.com




This annotation was added by the e-scan service.
http://www.activis.com
----------------------------------------------------------------------------
------
This message has been checked for all known viruses by e:)scan.
For further information please contact [EMAIL PROTECTED]

Reply via email to