With the code I have to maintain, I am overjoyed to see
open FILE, "file" or die;. Most of the time it is just
open FILE "file";.
Error handling is not a one size fits all proposition. You scale it with the size and importance of your program, and severity and likelihood of the error. If I am writing a one timer, I might not check return values at all; other times, I am going to be as paranoid as possible, checking and double checking everything I can. It is a matter of using the correct amount of error handling for your situation, instead of applying it with a trowel to get as much in there as you can.
As for burning the midnight oil, I have had to wade through hard to maintain, overly elaborate, and downright buggy error handling schemes at odd hours, where a simple
or die; would have told me what I needed to know immediately. The developer responsible refused to acknowledge there was such a thing as too much error handling, or that its complexity made his code less reliable, not more.
We shouldn't be advocating error handling for error handling's sake alone. It is a judgement to be made based on a number of program specific factors. As for code without context, like the snippets offered here, determinations about the "correct" level of error handling can only be made on the coarsest of levels.
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.