Skip to content

Instantly share code, notes, and snippets.

@A-pZ
Last active August 21, 2017 03:22
Show Gist options
  • Save A-pZ/d93413dd1ad0d58992d60b9a1ea92e1b to your computer and use it in GitHub Desktop.
Save A-pZ/d93413dd1ad0d58992d60b9a1ea92e1b to your computer and use it in GitHub Desktop.
OrElseThrowを使ってnull時は例外スロー&その他の処理をする
public class OrElseThrowSnipet {
void sample() {
List<String> list = new ArrayList<>();
list.stream().findFirst().orElseThrow(
() -> {
log.warn("error.");
throw new RuntimeException("elseThrowで例外を発生しました");
}
);
}
}
@A-pZ
Copy link
Author

A-pZ commented Aug 21, 2017

throw new RuntimeExceptionダメ絶対

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