3 ms·
Cool stuff, much appreciated. I notice that the code contains the use of 'goto' to handle an error condition. Seems clean. Being somewhat of a intermediate
by poutine 17y ago
Cool stuff, much appreciated.
I notice that the code contains the use of 'goto' to handle an error condition. Seems clean.
Being somewhat of a intermediate programmer I've always read to stay away from 'goto'. Anyone care to comment on the use of it in Objective-C?
- Empact 17y agoIn this case, he's emulating the effect of an exception in a language which doesn't support them particularly well[1]: logging the exception message and then moving to a "rescue" or "catch" block which does necessary cleanup. This is one of the few uses of goto which I find acceptable, and it's only necessary because these languages lack exceptions. Using goto for normal control flow, or even complex error handling, can be quite the nightmare. Particularly bi-directional gotos. Given the situation though, that it seems he's avoiding exceptions out of habit or performance concern, I'd still use an exception in this case, rather than the goto, to protect myself from probable misuse and unpredictability. [1] according to this http://stackoverflow.com/questions/324284/how-to-throw-an-exception-in-objective-c-cocoa http://stackoverflow.com/questions/324284/how-to-throw-an-ex..., objective-c has exceptions, but they're resource intensive and should be avoided.