Hacker News new | ask | show | jobs
by ICWiener 4118 days ago
> Wait a second--is this really using exceptions for control flow?

No.

If it used exceptions for control-flow, the defined function would actually throw an exception. Here, we catch "Exceptional Problems" and ignore them at most 3 times. A common example of using non-local exit is to return from deeply nested recursive calls.

(edit: of course, you can argue that network delays are not exceptional (surley you love Go), but the code shown by OP is supposed to handle any kind of exceptional situations. Of course, if there was an error value, you could define another function that checks that error value)

That being said, "Exceptions for exceptional situations" is exactly like "never use goto". Non-local exits are definitely useful and not necessarly costly.

> Performance is terrible in almost every language

Even in cases where this is true, it can make sense to use them for control flow according to your requirements and actual measures.

1 comments

> Here, we catch "Exceptional Problems" and ignore them at most 3 times.

You realize that catching and ignoring an exception is using exceptions for control flow, right?