Last active
August 21, 2017 03:22
-
-
Save A-pZ/d93413dd1ad0d58992d60b9a1ea92e1b to your computer and use it in GitHub Desktop.
OrElseThrowを使ってnull時は例外スロー&その他の処理をする
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class OrElseThrowSnipet { | |
void sample() { | |
List<String> list = new ArrayList<>(); | |
list.stream().findFirst().orElseThrow( | |
() -> { | |
log.warn("error."); | |
throw new RuntimeException("elseThrowで例外を発生しました"); | |
} | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
throw new RuntimeExceptionダメ絶対