Skip to content

Instantly share code, notes, and snippets.

@fo2rist
Last active July 6, 2019 00:05
Show Gist options
  • Save fo2rist/1aa03defd58da0fc2118fbaea4f29152 to your computer and use it in GitHub Desktop.
Save fo2rist/1aa03defd58da0fc2118fbaea4f29152 to your computer and use it in GitHub Desktop.
Initialization example
// try-fail-catch approach
try {
doMainAction()
} catch (exc: SomePreconditionViolated) {
doFallbackAction()
}
/* ^ COMPARE v */
// check-and-execute approach
if (canDoTheAction()) {
doMainAction()
} else {
doFallbackAction()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment