One of the things I like about DBI is that I can automatically trap errors.
my $dbh = DBI->connect("dbi:ODBC:$DSN", $USER, $PASSWORD, {RaiseError +=> 1});
That RaiseError statement allows subsequent calls to the database to automatically die with a message on an error. If you don't add that and fail to check for success or failure, your program can chug silently along, functioning incorrectly, without you having a clue until your boss yells at you.

My dilemma: the company that I work for has a lot of legacy code in modules that opens files, reads them, establishes database connections, etc., ALL WITHOUT CHECKING FOR SUCCESS OR FAILURE!!! I am going through and fixing these things when I find them, but I am wondering if their is a way to automatically kill your Perl script if something like open FILE, $somefile fails? I'm not talking about adding or die on all of these. I'm doing that now. I'm wanting something that will autokill the script if $! is set. That would just be a stopgap workaround, but I need to have something in place until I can plug all of the holes. (Yes, I know that most database connection failures don't set $!. Checking for a change in $! would catch the bulk of the problems).

Until I get all of these things fixed, this is going to be a nightmare. As is stands now, I just spent a couple of hours finding a bug in a huge script that I would have found immediately had they just put an "or die" after a stinkin' open statement!

Cheers,
Ovid


In reply to Error trapping by Ovid

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.