My practices are these.
I always make sure that it would be clear from the error message that it's an error. I don't use a single prefix, just include one some word like qw"error cannot failed failure". It can be very confusing if you write
read $FOO, $s, $l or do {
warn "reading foo file";
last PROCESS_FOO;
}
because it will seem to be a status message saying the program is starting to read the foo file.
I always include $! if its value is meaningful (that is, if the function that fails sets it).
I always provide the implicit line number (although I almost always ignore it when I read the error message). The exception is some status messages that are not errors.
I don't capitalize the error message.
I sometimes give details about the error, sometimes not. I add the details in the die statement if the error actually happens and I don't understand why.
If you want to know more about my style, here is the complete (ok, I could have missed some) list of error statements in two of my programs.
1 < ($scope = 0 + $scope) or
die "nearword scope must be greater than 1";
open $file, "<", $filename or
die "cannot open text file for nearword: $!";
$nl <= $n && $n <= $nle or
die "postcondition failed";
@a or
die "internal error: quantile1 called on empty
+ list, n=" . $n;
@{$hheap[1]} and # DEBUG
die "internal error: couldn't pop non-
+empty hheap";
$used{$q}++ and
warn "single-link internal: used hash corrupt"
+;
@order == @point && @gap == @order or
die "singlelink internal error: lost or duplicate elem
+ents: order " . @order . ", point " . @point . ", gap " . @gap;
keys(%$hash) == @$heap or
die "assertion failed: hheap size mismatch: hash " . k
+eys(%$hash) . ", heap " . @$heap;
for $k (0 .. @$heap - 1) {
ref($$heap[$k]) eq "ARRAY" or
die "assertion failed: non-array heap element
+index " .
$k;
exists($$hash{${$$heap[$k]}[1]}) or
warn("assertion failed: hheap element missing
+from hash: "), die "index " . $k . ", element " . ${$$heap[$k]}[1] .
+", distance " . ${$$heap[$k]}[0];
$k == $$hash{${$$heap[$k]}[1]} or
warn("assertion failed: hheap index mismatch:
+"), die "
real index " . $k . ", element " . ${$$heap[$k]}[1] . ", hash value
+ " . $$hash{${$$heap[$k]}[1]};
${$$heap[($k - 1) >> 1]}[0] <= ${$$heap[$k]}[0] or
warn("assertion failed: hheap heap mismatch: "
+), die "parent index " . $k . ", element " . ${$$heap[$k]}[1] . ", di
+stance " . ${$$heap[$k]}[0] .
", child index " . (($k - 1) >> 1) . "
+, element
" . ${$$heap[($k - 1) >> 1]}[1] . ", distance " . ${$$heap[($k - 1) >>
+ 1]}[0];
1 == @ARGV or
die "Usage: rock-cut -g goal hierarchy.xml";
length($id) or
die "invalid input: element with no id";
exists($element{$id}) and
die qq[invalid input: duplicate element id "$i
+d"];
length($id) or
die "invalid input: cluster without id";
exists($cluster{$id}) and
die qq[invalid input: duplicate cluster id "$i
+d"];
@root or
die(@root ? "error: no root clusters found -- wierd" :
+ "error: no clusters found at all");
exists($$d{"weight"}) and do {
if (defined($$d{"weight"}))
{ warn qq[warning: cluster included in
+ more than one cluster: "$n"]; }
else
{ die qq[error: circular clusters: "$n
+"]; }
};
{ warn qq[cluster "$c" has non-existen
+t child "$cd"]; next; };
defined($mi) or do {
warn "clusters fragmented totally, decrease go
+al or outlier_max";
last;
};
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, 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, 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.
|
|