http://www.perlmonks.org?node_id=994234


in reply to Error handling

My philosophy is to validate the heck out of anything the user has to say. Concentrate all of the validation checks into one place and give the user actionable information about what is wrong and then assume in the rest of the code that the input is valid...well sort of...I give an example of some code that I am working on...
sub compare2records { my ($x, $y) = @_; # $x and $y are array refs to DB records my $result =0; #typical message might be.... #Argument "13ND" isn't numeric...blah...blah local $SIG{__WARN__} = sub { my $msg = shift; print STDERR "*******\n"; print STDERR $msg; #has a \n in $msg print STDERR "current DB record: id=", $x->[$dbc_id]; ...other complicated info for developers... print STDERR " other DB record: id=",$y->[$dbc_id],"\n"; print STDERR "*******\n"; }; ... complex comparisons happen here.... ... a non-numeric field in the DB that should be numeric will ... cause an error and will be intercepted by the SIGNAL handler ... these are messages intended for the develop team ... ... the user shouldn't see this, it means we screwed up on ... data validation and it is "our" problem, not a user ... problem! We have to fix code, this is past user has to ... fix his/her input! A user input error should not have ... gotten this far! }
The idea here is that this SIGNAL handler should never be executed. If it does execute, then the info is for the development team and we have to fix a problem regardless of the user. This is an example of "OUR" problem versus "YOUR" problem as a user. We have "our" problem because of some issue that we failed to tell you, the user about further upstream.

So, this is a bit of a mix. The further down in the code that an inconsistency is found, the more detailed and more cryptic the error message will be. Find the user input errors early. I don't expect the user to know what the heck an error between 453,203 and 129,385 means - something like that means that we (the SW team) screwed up.

In this application, I get 900+ files from 900+ sources, using 80+ programs to generate the files. Stuff happens. It is not possible to herd 900 chickens into the same roost without good SW or a lot of sheep dogs! Mixed metaphor, but I think you get the idea.