in reply to Re^5: Capturing error thrown by a database
in thread Capturing error thrown by a database

Hey Marshall.. I have already tried that.. I am pasting here the code snippet. Please advise.. eval { sub OpenSybaseConnection { my ($srv, $user, $pwd, $db) = @_; my $dbh; $FH1=$_4; print $FH1 "\n\nConnected to Server:$srv, Database:$db\n"; $dbh=DBI->connect("dbi:Sybase:server=$srv", $user, $pwd,{RaiseError =>1,PrintError =>1 }) || die $DBI::errstr; $dbh->do("use $db"); $common::conn_hdl = $dbh; }; }; if($@) { @proc_error=$@ ; print "inside if\n"; print "Check for if\n"; print "Hi:$@"; print "\nIn Common: @proc_error: HELP"; }
  • Comment on Re^6: Capturing error thrown by a database

Replies are listed 'Best First'.
Re^7: Capturing error thrown by a database
by Marshall (Canon) on Aug 01, 2011 at 14:59 UTC
    Please use <code> </code> tags around your code so that the line breaks are preserved. The eval{} goes around the dbi method code! Not around the subroutine! Anyway this is how to use eval... The connect asks to use RaiseError =>1 and I'm not sure that's in effect if the connect fails so I think the extra die is just fine- just in case. If the connect succeeds, the "do" happens next.
    sub OpenSybaseConnection { my ($srv, $user, $pwd, $db) = @_; my $dbh; $FH1=$_4; #???????????????????????????? eval { $dbh=DBI->connect( "dbi:Sybase:server=$srv", $user, $pwd, {RaiseError =>1, PrintError =>1} ) or die "Extra death $DBI::errstr"; $dbh->do("use $db"); }; if($@) # true if the eval failed (die'd at some point) { @proc_error=$@ ; print "inside if\n"; print "Hi:$@"; print "\nIn Common: @proc_error: HELP"; } else # this is the "no error" case { $common::conn_hdl = $dbh; print $FH1 "\n\nConnected to Server:$srv, Database:$db\n"; } return; }
      Wao Marshall... Thanks a lot.. My purpose is solved and u were a great help to me.. I was stuck with this issue for quite sometime now... Thanks to you that my problem is solved..
Re^7: Capturing error thrown by a database
by Marshall (Canon) on Aug 01, 2011 at 15:02 UTC
    dupe post for some reason..