On Wed, 2 Jul 2003 09:08:05 -0400 Hardy Merrill <[EMAIL PROTECTED]>
wrote:
> Michael A Chase [EMAIL PROTECTED] 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
>
> I'm not sure I understand. According to the DBI perldocs
> on RaiseError:
>
> "RaiseError" (boolean, inherited)
> This attribute can be used to force errors to raise exceptions
> rather than simply return error codes in the normal way. It is
> "off" by default. When set "on", any method which results in
> an error will cause the DBI to effectively do a "die("$class
> $method failed: $DBI::errstr")", where $class is the driver
> class and $method is the name of the method that failed.
>
> My impression is that RaiseError => 1 causes a "die" to occur
> on any DBI error. Not true with RaiseError on connect? I'm
> probably just missing something - it's early ;-)
I might have been more clear. I meant to point out that the 'or die'
clause in the connect() statement would never be executed if
{RaiseError => 1} was in the connect() argument list. If the intent
was to have more control over the error message, Ian would need to have
RaiseError off during connect().
I also should have mentioned that $dbh->errstr and $DBI::errstr have
the same content until the next DBI method call.
> I've typically used RaiseError => 1 and surrounded connect with
> an eval - not sure what the difference is between that and
> having RaiseError cause a die on the connect. What am I
> missing?
Nothing, you are just trapping the internal 'die()' caused by
RaiseError. That's another way to gain control without having to
explicitly set RaiseError to 1 after the connect().
--
Mac :})
** I normally forward private questions to the appropriate mail list. **
Ask Smarter: http://www.catb.org/~esr/faqs/smart-questions.html
Give a hobbit a fish and he eats fish for a day.
Give a hobbit a ring and he eats fish for an age.