in reply to Re: DBI: pass $dbh from a sub
in thread DBI: pass $dbh from a sub

The DBI->connect method does not follow the RaiseError property. It returns undef on an error and sets the $DBI::errstr. The return value needs to be tested, although it is more useful to use die instead of warn.

Replies are listed 'Best First'.
Re^3: DBI: pass $dbh from a sub
by runrig (Abbot) on Jul 29, 2004 at 20:39 UTC
    The DBI->connect method does not follow the RaiseError property. It returns undef on an error...
    It used to be that way, but hasn't been for quite a while. Check the changes log.
      yes, this was fixed some time ago, the Changes file in the DBI distribution says...
       Changes in DBI 0.91,	10th December 1997
        ...
        DBI->connect(..., { RaiseError=>1 }) now croaks if connect fails.
        ...
      
Re^3: DBI: pass $dbh from a sub
by mifflin (Curate) on Jul 29, 2004 at 16:50 UTC
    It doesn't behave that way for me.
    The code...
    use DBI; eval { $dbh = DBI->connect('dbi:Oracle:dev', 'bad', 'pass', {RaiseError => + 1, PrintError => 0}) || warn "warning"; print "after connect\n"; }; if ($@) { print "Ugh!\n"; }
    will not print out "warning" or "after connect"
    it prints out "Ugh!"
    # perl testit Ugh!
Re^3: DBI: pass $dbh from a sub
by poqui (Deacon) on Jul 29, 2004 at 19:53 UTC
    But I avoided "die" because I don't want my program to end at that point; doesn't "die" exit the program?
      ...doesn't "die" exit the program?
      Not when it is in an eval block. eval is perl's way of "trying" a block of code, and die is like throwing an exception, and checking $@ afterward is like catching the exception.
        OIC!
        So an eval is like its own little segregated program space?