Ned Batchelder: Exceptions vs. status returns
Broadly speaking, there are two ways to handle errors as they pass from layer to layer in software: throwing exceptions and returning status codes. Almost everyone agrees that exceptions are the better way to do it, but some people still prefer status returns. This article shows why exceptions are better.
I've been thinking about the issue some lately, as I've been annoyed that Python's (and Ruby's... haven't tried Perl's for this) FTP library throws exceptions in places where just a return value might be easier to deal with... For instance, I want to change to a directory on an FTP server, but if the directory doesn't exist, create it. To me, something like:
if not ftp.cwd(settings['remote-dir']):
print "Couldn't change to directory (",e,").
Making directory",settings['remote-dir']
if not ftp.mkd(settings['remote-dir']):
print "Error, couldn't make directory:", e
ftp.close()
sys.exit(1)
else:
ftp.cwd(settings['remote-dir'])
is much easier than:
try:
print ftp.cwd(settings['remote-dir'])
except ftplib.error_perm, e:
try:
print "Couldn't change to directory (",e,").
Making directory",settings['remote-dir']
ftp.mkd(settings['remote-dir'])
except e:
print "Error, couldn't make directory:", e
ftp.close()
sys.exit(1)
else:
ftp.cwd(settings['remote-dir'])
(code reformatted a bit to fit)
Not a great example, and maybe exceptions are better even in this case because they'll kill your program if the second "cwd" fails so you won't be working in an inconsistent state.
Anyway, just thinking out loud... I'm not totally comfortable with exceptions since I didn't "grow up" using them. I'd write more or think more... but I gotta get to bed.
Here's a neat article at Slate I heard about on Rush today: Pious Bias "Lies and the lying liars who attribute them to the other party."
I guess the article was written before three liberal judges of the 9th Circus court of appeals (two Clinton appointees and one Carter appointee) decided to ignore the law of the state of California and the will of the state's voters and illegally postpone the election date because the same voting machines that elected Davis this past election and which have been in use for decades, somehow aren't "fair" anymore. They don't care about the machines when they elect Democrats, but now that a Republican has a chance to win the election the machines are no good anymore. So they want to postpone the election until May, which if I understand correctly is the date of the Democratic primary election in that state, when you're bound to get more Democrats voting then you will in the October election. Talk about election shenanigans. What an out-of-control judiciary. Sheesh.
Inktomi is the worst spider ever. Not only is it still looking for pages I removed from my site years ago (and redirected to new locations years ago), but it continues to look for pages that have never existed on my site. Argh!
I hate ASP.NET
I hate ASP... I was doing wonderswith PHP, then suddenly one of myclients...
Johnies: Mar 17, 6:14am