Is this the idea? I do not ever want to catch the error from the prepare 
statement itself -- I want my code to catch and throw the error.  And I am 
using Perl 5.8 so I do not need the use 5.010; pragma ....  thx 

use strict;
use warnings;
use 5.010;  

eval {
    my $sth = $dbh->prepare("SELECT COUNT(*) FROM mytable");   
};

if ($dbh->err) {
  print "Table $table -- DOES NOT EXIST\n";
}
$retCode = $sth->execute();
 
--- On Mon, 1/2/10, 7 <7stud.7s...@gmail.com> wrote:


From: 7 <7stud.7s...@gmail.com>
Subject: Re: prepare(SELECT ... FROM TABLE) error
To: "Beginners Perl" <beginners@perl.org>
Date: Monday, 1 February, 2010, 14:05


On Mon, Feb 1, 2010 at 12:11 PM, Tony Esposito
<tony1234567...@yahoo.co.uk>wrote:

> when the table does not exist the prepare fails.  How do ignore the error
> thrown by the prepare() and catch it later in the program?
>
>
> my $dbh = DBI->connect("dbi:ODBC:mysql"
>                          ,$login
>                          ,$passwd
>                          ,{ RaiseError => 0 }
>                         );
> ...
> $sth = $dbh->prepare("SELECT COUNT(*) FROM mytable");   # don't catch
>  $retCode = $sth->execute();
> if ($dbh->err) {
>   print "Table $table -- DOES NOT EXIST\n";
> }
> ....
>



See if this helps:


use strict;
use warnings;
use 5.010;


eval {
    die "***prepare error***";
};

say 'executing other code here';

if ($@) {
    say "There was an error inside that eval block above: $@";
}



 
 
 
 
 
 
 
> my $dbh = DBI->connect("dbi:ODBC:mysql"
>                          ,$login
>                          ,$passwd
>                          ,{ RaiseError => 0 }
>                         );
> ...
> $sth = $dbh->prepare("SELECT COUNT(*) FROM mytable");   # don't catch
>  $retCode = $sth->execute();
> if ($dbh->err) {
>   print "Table $table -- DOES NOT EXIST\n";
> }
> ....
>



See if this helps:


use strict;
use warnings;
use 5.010;


eval {
    die "***prepare error***";
};

say 'executing other code here';

if ($@) {
    say "There was an error inside that eval block above: $@";
}


--- On Mon, 1/2/10, 7 <7stud.7s...@gmail.com> wrote:


From: 7 <7stud.7s...@gmail.com>
Subject: Re: prepare(SELECT ... FROM TABLE) error
To: "Beginners Perl" <beginners@perl.org>
Date: Monday, 1 February, 2010, 14:05


On Mon, Feb 1, 2010 at 12:11 PM, Tony Esposito
<tony1234567...@yahoo.co.uk>wrote:

> when the table does not exist the prepare fails.  How do ignore the error
> thrown by the prepare() and catch it later in the program?
>
>
> my $dbh = DBI->connect("dbi:ODBC:mysql"
>                          ,$login
>                          ,$passwd
>                          ,{ RaiseError => 0 }
>                         );
> ...
> $sth = $dbh->prepare("SELECT COUNT(*) FROM mytable");   # don't catch
>  $retCode = $sth->execute();
> if ($dbh->err) {
>   print "Table $table -- DOES NOT EXIST\n";
> }
> ....
>



See if this helps:


use strict;
use warnings;
use 5.010;


eval {
    die "***prepare error***";
};

say 'executing other code here';

if ($@) {
    say "There was an error inside that eval block above: $@";
}


--output:--
executing other code here
There was an error inside that eval block above: ***prepare error*** at
2perl.pl line 7.



      

Reply via email to