Exception handling and resource cleanup

Ken Raeburn raeburn at MIT.EDU
Tue Apr 7 20:43:52 EDT 2009


On Apr 7, 2009, at 16:15, Sam Hartman wrote:
> However I either don't know how to do if-ladder with loops or it
> doesn't work well.  Take a look at prepare_as_error in do_as_req.c.  I
> think that code would have been better using goto-one-label.

The first thing I found looking for for loops in kim/lib/mac was that  
the loop condition checks for the error or other exit condition, in  
addition to whatever else.  So instead of "loop up to N times"/"break  
out on error", you write "loop until we get an error or have done it N  
times".  It seems like a logical extension to the "instead of writing  
goto/break, set and test this variable" approach.

If it can give real benefits over goto-one-label, great.  But I  
wouldn't want to use it just because it lets us avoid a certain four- 
letter keyword people have been taught to have a knee-jerk reaction  
to, and it doesn't magically make spaghetti logic impossible.  I  
haven't spent much time reading if-ladder code, and I'm sure it would  
get easier as I get used to it, so I don't want to say too much  
against it (or, what I do say should be weighed accordingly), but so  
far, I find "on error, go down to this cleanup label" easier to follow  
than "on error, skip over this block... skip over this block... skip  
over this block... skip over this block... okay, here's the cleanup  
code".  Multiple cleanup labels for a block, not so much, and I've  
been guilty of writing that way at times, but a single cleanup label  
doesn't seem unreasonable to me.

Ken



More information about the krbdev mailing list