Return Early
# Return Early
- Return Early Pattern. A rule that will make your code more… | by Leonel Menaia | The Startup | Medium
- Structured programming - Wikipedia
- Rust Error Handling
public String returnStuff(SomeObject argument1, SomeObject argument2){
if (!argument1.isValid()) {
throw new Exception();
}
if (!argument2.isValid()) {
throw new Exception();
}
SomeObject otherVal1 = doSomeStuff(argument1, argument2);
if (!otherVal1.isValid()) {
throw new Exception();
}
SomeObject otherVal2 = doAnotherStuff(otherVal1);
if (!otherVal2.isValid()) {
throw new Exception();
}
return "Stuff";
}

- Fail fast
- Single Entry, Single Exit (SESE)
# Disadvantage
- Unable to clean resources