[Edu-sig] What do files and exceptions have in common?
john.zelle at wartburg.edu
Mon Nov 8 02:56:56 CET 2004
Kent Johnson wrote:
> Still prepping for my files class. The chapter in Dawson is "Files and
> Exceptions". I think that is a little strange; what do files and
> exceptions have to do with each other, pedagogically? None of the file
> examples even use exceptions, and few of the exceptions examples use
> But whatever, I figure I'll stick with the program. But looking at
> other sources, I see Elkner's "Hot to Think Like a Computer Scientist"
> and Mark's "Dive into Python" have chapters called "Files and
> Exceptions" and "Exceptions and File Handling" respectively.
This is interesting. Could this be related to the fact that File
processing in Java _forces_ one to understand exceptions (since they
either have to be handled or thrown)? If the authors are modeling their
approach on a Java book, this would be very natural. Of course, the fact
that Java forces this suggests that exception handling is an important
facet of file IO at some level.
We all have our favorite order for doing things. In my book, I introduce
files in an early chapter on string processing. Text files are really
just multi-line strings. The ideas are reinforced later in a chapter on
looping structures, since reading until end-of-file is a particularly
common kind of loop.
I like to talk about exceptions as a special kind of decision structure
(in languages w/o exceptions, you would check returned error codes with
ifs). So I put exceptions into a chapter on decisions (ifs).
To each his own.
More information about the Edu-sig