KBD

Keith Devens .com

Saturday, November 22, 2008 Flag waving
"To know what *would* have happened, child?" said Aslan. "No. Nobody is ever told that." – C.S. Lewis (Aslan, in Prince Caspian, Chapter 10)

Archive: September 16, 2003

← September 15, 2003September 17, 2003 →

Daily link icon Tuesday, September 16, 2003

Exceptions vs. status returns

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.

Neat article at Slate

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

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!

← September 15, 2003September 17, 2003 →
November 2008
SunMonTueWedThuFriSat
 1
2345678
9101112131415
16171819202122
23242526272829
30 



RSS feed RSS feed for Keith's Weblog
Atom feed Atom feed for Keith's Weblog
Weblog archive
Recent comments
  on 4 posts

Recent comments XML

Calif. Supreme Court to take up gay marriage ban

I would argue the point is not​definitional.  While the word​marriage is su...

Justin: Nov 20, 4:37pm

Java join function

Meh, don't have null strings in​your string arrays imo, but you're​welcome ...

Keith: Nov 19, 7:51pm

Girls, please don't get breast implants

sorry but another thing i have to​make a comment on about you​men...the men...

happynow: Nov 17, 11:36pm

Books by Vincent Cheung

to all Cheung​fans:

read:

http://www.progin​osko.com/aquascum/cheung.h...

Zamir: Nov 16, 9:07am

Generated in about 0.041s.

(Used 7 db queries)

mobile phone