Permalink
Browse files

Exceptions

  • Loading branch information...
1 parent a660875 commit 31cb8e495f0ae6c8e765ab53adcd7ea26ebcf904 matias alejo garcia committed Oct 15, 2012
Showing with 41 additions and 3 deletions.
  1. +8 −0 lib/SQL/Bibliosoph.pm
  2. +2 −2 lib/SQL/Bibliosoph/CatalogFile.pm
  3. +27 −0 lib/SQL/Bibliosoph/Exceptions.pm
  4. +4 −1 lib/SQL/Bibliosoph/Query.pm
View
@@ -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
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
n. person having deep knowledge of books. bibliognostic.
@@ -119,8 +119,8 @@ package SQL::Bibliosoph::CatalogFile; {
my $FH;
open ($FH,$file)
or SQL::Bibliosoph::Exception::CatalogFileError->throw(
- desc => "Could not read \"".$file."\" : $!"
- ) if ! -e $file;
+ desc => "Could not read \"".$file."\" : $!"
+ );
my @all = <$FH>;
close ($FH);
@@ -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;
@@ -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
SQL::Bibliosoph::Exception::QuerySyntaxError->throw (
desc => $e,

0 comments on commit 31cb8e4

Please sign in to comment.