Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

comment on

( [id://3333] : superdoc . print w/replies, xml ) Need Help??

I was trying to put a custom handler for the error being raised by SQLite. Below is the snip of the sub routines which I put down.

sub handle_error { my $message = shift; my $database = shift; if ( its a connection error ) { log an error and exit else log an error and continue } sub initDB { my $dbh = shift; my $database = shift; my $driver = "SQLite"; my $dsn = "DBI:$driver:dbname=$$database"; my $userID = ""; my $password = ""; $$dbh = DBI->connect($dsn, $userID, $password, {RaiseError => 1, PrintError => 0, HandleError => \&handle_error, AutoCommit => 0 } ) or handle_error(DBI->errstr, $$database); $$dbh->do("PRAGMA synchronous=OFF"); }

Now is there a way I can identify its an connection error or some other error e.g. say insert operation fails. As I want to use a generic function which take cares of logging the errors based on the error.


In reply to SQLite handling of errors through common function by techman2006

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.