Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: Error handling

by Marshall (Prior)
on Sep 18, 2012 at 08:20 UTC ( #994234=note: print w/ replies, xml ) Need Help??


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.


Comment on Re: Error handling
Download Code
Re^2: Error handling
by Ari (Novice) on Sep 18, 2012 at 13:37 UTC
    I think this approach was what I was leaning towards. I'm still building the validation for the initial input. After that, the program *should* work correctly. If the user (or, eventually, file) contains the wrong initial ID then the resulting answer won't be what they were expecting, but it will be correct. (At least, that's my hope. This is my first project, so I'm building it in stages and learning as I go!)

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://994234]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (8)
As of 2014-12-22 07:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (112 votes), past polls