[Tutor] Error handling in functions / main program

Klas Marteleur klas.martelleur at telia.com
Thu Aug 12 17:09:19 CEST 2004


My convert program that should convert one text file to another text file is 
now built of three functions:

def readInput(inputFile):
Which opens and reads a file into a list and splits it to elements. It returns 
a list.

def modifyList(inputList,latestRevision):
Which takes the "splited" list and a 1 or a 0 as latestRevison to perform or 
not perform some "extra" modifications on the list. This function returns a 
modified list.

def writeListToFile(inputList, outputFile):
This function writes the modified list (inputList) to a file(outputFile). 
Returns nothing

and a:

if __name__=='__main__':
which executes the functions very basic. No user input yet

...and i am also planing to write a little GUI in another file
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.

I mean i could add a lot of extra error checking in the functions (... so that 
correct inputs are used etc)? Or should that be the responsebility of the 
main program to asure that the input to the functions are correct?
Then what type of error handling should be located in the functions?

I hope my questions wasnt to confusing (english is not my native language).

Kind regards

More information about the Tutor mailing list