Skip to content

Instantly share code, notes, and snippets.

@Swatinem
Created May 15, 2013 16:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Swatinem/5585263 to your computer and use it in GitHub Desktop.
Save Swatinem/5585263 to your computer and use it in GitHub Desktop.
The Java way of doing control flow
// the java way of doing control flow
try {
init;
for (;;) {
try {
if (!condition)
throw new ConditionNotMetExpection();
if (foo)
throw new ContinueExpection();
if (bar)
throw new BreakExpection();
update;
} catch (ContinueExpection e) {}
}
} catch (BreakExpection e) {}
catch (ConditionNotMetExpection e) {}
// same shit for while/do-while
// and function calls:
void Method() throws Throwable {
throw new ReturnValueExpection(someValue);
}
Object returnValue;
try {
Method();
} catch (ReturnValueExpection e) { returnValue = e.getValue(); }
@ysangkok
Copy link

Why is this the Java way, you're the one throwing the exceptions here? Java even has labels so you can break multiple loops without resorting to stuff like this. Python has no labels, and uses exceptions for generators. So I don't know why you picked Java as your target.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment