It's a personal preference thing, although, mine is pretty strong
towards using gotos for error handling.

It allows you to have two exit points from a function, success and
failure.  This is useful for:

- Setting breakpoints on function exit, and on error
- Counting statistics on error (in one place, vs multiple)
- Code readability (all of the error handling ends up being in a single place.)

It's somewhat of a poor man's exceptions.

In general, I don't really use goto's for anything else but error
handling.  Sometimes to quickly hack loop logic (i.e. to exhaust a
queue), but I generally end up replace it with a nested loop in that
case.

Sterling


On Tue, Nov 10, 2015 at 12:15 AM, Justin Mclean
<[email protected]> wrote:
> hi,
>
> Just curious re the use of "goto err” vs multiple returns in a function. Is 
> there any reason the goto is preferred?
>
> Thanks,
> Justin

Reply via email to