KBD

Keith Devens .com

Thursday, November 20, 2008 Flag waving
Darwin made it possible to be an intellectually-fulfilled atheist. – Richard Dawkins (The Blind Watchmaker)
← Things I'll spend money on if I get a jobRDS →

Daily link icon Thursday, December 18, 2003

Programming without exceptions

Internet Alchemy: Programming without exceptions. I haven't followed all the links yet, but this seems pretty much like my philosophy on exceptions.

If you have a function that does one thing, and there's a clear way for it to fail in that task, and there aren't lots of ways for it to fail where you need to distinguish exactly how it failed, and there's bandwidth (which I'll explain in a bit) in the function's return value for a failure value (or maybe in a parameter list if you're passing pointers (or "by ref" arguments) around), then return it from the function rather than using exceptions, which like the post at Internet Alchemy points out, are essentially "non-local gotos".

Sorry for the run on sentence. By bandwidth I mean something like if a function is only supposed to return positive integers, an easy way to signal failure is by returning zero or a negative number. Or if your function is supposed to return an object or a pointer to something, make it return null.

malloc is a choice example of this. Returning null is an easy and unambiguous way for it to tell you it failed.

← Things I'll spend money on if I get a jobRDS →

Comments XML gif


Feel free to post a comment below. Please see my comment policy.

Formatting Rules (No HTML):

  • **bold**, *italic*, _underlined_, --strikeout--
  • "text"="url" creates a link, and URLs are auto-highlighted
  • Blockquote: Like e-mail, begin paragraph with > (greater-than sign)
  • Lists: begin paragraph with *,-, or + (unordered), or # (ordered)
  • Code block: ?!code:language=perl|php|sql|javascript|etc.{\n}...{\n}?!/code

:
(will be your IP address if blank)
: (optional)
(Will not be shown on site)

: (optional)
:

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

new⇒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

Spider solitaire

To undo or not to undo that is the​question.
I'm an undoer. 
My dad​was n...

Can Turk: Nov 15, 2:50pm

Generated in about 0.189s.

(Used 8 db queries)

mobile phone