[Tutor] Error handling in functions / main program
Alan Gauld
alan.gauld at blueyonder.co.uk
Thu Aug 12 22:48:46 CEST 2004
> Now to my questions:
> How much and what type of error handling should be handled by:
> 1. The functions
> 2 The main program / GUI program.
That's a very profound question with no easy answer.
The C language takes the approach that the user checks
the inputs before passing them - it leads to faster code.
Other languages tend to expect the function to do
validation - very common in web page development and
in financial apps in COBOL.!
Python has the tenet of its better to ask forgivness
than permission, which tends to be interpreted as put
the function code inside a try except and catch the
possible erors. If the data is good there is minimal
overhead, if its bad you pay the provce but still
get a "safe" program. And of course the function
can "raise" exceptions for the client program to catch.
So no clear cut answer, but maybe a hint.
Alan G.
More information about the Tutor
mailing list