Structured exception handling is a powerful way to describe how your program reacts to error conditions. But it's not available in a language like C, and thus C programmers have come up with a variety of ways to propogate errors. Frequently, functions simply return error codes. Some error handling practices use the dreaded goto to jump to the error handler.

Or, they do what "Maple Syrup"'s predecessor did for all of their error handling code:

do {
  // ...
  if (failureCondition)
  return TRUE;
} while (0);
// failure case treatment...

Now, if you check the comments on this article about an hour or two after posting, you'll see some lovely essays describing why this particular construct is the best possible option to use in certain cases, and that it's definitely not a WTF and it shouldn't be posted on this site.

But in the meantime: just look at it. At its core, it reinvents the goto by exploiting the break keyword inside of a loop that will never repeat.

It works, despite the syntactical noise it adds to the code. Is it how any of these constructs should be used? No, but in the words of William Gibson: the street finds its own uses for things.

[Advertisement] Utilize BuildMaster to release your software with confidence, at the pace your business demands. Download today!