I was just giving an example of my own code. This was something I pulled out of a script. You are correct about the line or code which gets me my database handle. So perhaps, it wasn't the best of examples. The point that I was trying to make was that after you do get a database handle, you can then manage the errors better. This particular script that I took the example from is something I run in a cron. So, I have the script set up to just die if I am unable to initialize everything properly. When that happens it is written to STDERR and I will be notified via email that something is wrong. All the other stuff in the script gets logged.

Michael A Chase wrote:

On Tue, 01 Jul 2003 16:12:09 -0600 Ian Harisay <[EMAIL PROTECTED]>
wrote:



Doing the redirect can be a bit clunky.  If you want to be more
precise with how you handle these errors, add this $attr to your
connect statement.

my $attr = { PrintError => 0, RaiseError => 1, AutoCommit => 0 };
my $dbh = DBI->connect( @{$login}, $attr )
 or die "Can't connect to Oracle database: $DBI::errstr\n";

then when an error occurs it will not print to STDERR. Rather it
can be read thru $dbh->errstr.



Did you mean 'RaiseError => 0'? With 'RaiseError => 1', connect() never returns if an error occurs. In either case (RaiseError or die), the output goes to STDERR.

When I need to force STDERR to another place, I use open().
Note the autoflush() as well, otherwise the order of output lines
going to a file may be incorrect since STDERR is not buffered.

  open( LOG, ">> $file" );
  autoflush LOG 1;
  open( STDERR, ">&=" . fileno( LOG ) );






Reply via email to