Skip to content

Commit

Permalink
Exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
matias alejo garcia committed Oct 15, 2012
1 parent a660875 commit 31cb8e4
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 3 deletions.
8 changes: 8 additions & 0 deletions lib/SQL/Bibliosoph.pm
Expand Up @@ -720,6 +720,14 @@ printed to STDERR after each query execution, if the time is bigger that
To enable debug (prints each query, and arguments, very useful during To enable debug (prints each query, and arguments, very useful during
development). development).
=head3 throw_errors
Enable by default. Will throw SQL::Bibliosoph::Exceptions on errors. If disabled,
will print to STDERR. By default, duplicate key errors are not throwed are exception
set this variable to '2' if you want that.
=head3 duplicate_key
=head1 Bibliosoph =head1 Bibliosoph
n. person having deep knowledge of books. bibliognostic. n. person having deep knowledge of books. bibliognostic.
Expand Down
4 changes: 2 additions & 2 deletions lib/SQL/Bibliosoph/CatalogFile.pm
Expand Up @@ -119,8 +119,8 @@ package SQL::Bibliosoph::CatalogFile; {
my $FH; my $FH;
open ($FH,$file) open ($FH,$file)
or SQL::Bibliosoph::Exception::CatalogFileError->throw( or SQL::Bibliosoph::Exception::CatalogFileError->throw(
desc => "Could not read \"".$file."\" : $!" desc => "Could not read \"".$file."\" : $!"
) if ! -e $file; );


my @all = <$FH>; my @all = <$FH>;
close ($FH); close ($FH);
Expand Down
27 changes: 27 additions & 0 deletions lib/SQL/Bibliosoph/Exceptions.pm
@@ -0,0 +1,27 @@
#===============================================================================
#
# FILE: Exceptions.pm
# CREATED: 07/13/2008 07:00:36 AM ART
#===============================================================================

use strict;
use warnings;

package SQL::Bibliosoph::Exceptions;

use Exception::Class (
'SQL::Bibliosoph::Exception::QuerySyntaxError' => {
description => 'Syntax Error',
fields => [ qw(desc) ],
},
'SQL::Bibliosoph::Exception::CallError' => {
description => 'Function Call Error',
fields => [ qw(desc) ],
},
'SQL::Bibliosoph::Exception::CatalogFileError' => {
description => 'Catalog File Error',
fields => [ qw(desc) ],
},
);

1;
5 changes: 4 additions & 1 deletion lib/SQL/Bibliosoph/Query.pm
Expand Up @@ -202,7 +202,10 @@ package SQL::Bibliosoph::Query; {
. '\"' . '\"'
; ;


if ($self->throw_errors() ) { if (
$self->throw_errors() == 2
|| ($self->throw_errors() == 1 && $e !~ /\sDuplicate entry\s/ )
) {
# $sth->err and $DBI::err will be true if error was from DBI # $sth->err and $DBI::err will be true if error was from DBI
SQL::Bibliosoph::Exception::QuerySyntaxError->throw ( SQL::Bibliosoph::Exception::QuerySyntaxError->throw (
desc => $e, desc => $e,
Expand Down

0 comments on commit 31cb8e4

Please sign in to comment.