Skip to content

Instantly share code, notes, and snippets.

@tokiwoousaka
Last active August 29, 2015 13:57
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 tokiwoousaka/9783721 to your computer and use it in GitHub Desktop.
Save tokiwoousaka/9783721 to your computer and use it in GitHub Desktop.
"@zakky_dev: Aの処理に失敗したらBをやり、それにも失敗したらCをやり、そこで失敗したら例外をスローする。どの処理でも成功したらDの処理を実行する。こういったことやりたいのかなりあるんだけど、どうしよっかなー。" https://twitter.com/zakky_dev/status/448654622970753024
public class Main {
private static void procces(boolean success, String procName){
if(success){
System.out.println("処理 " + procName + " 成功");
throw new RuntimeException();
}
System.out.println("処理 " + procName + " 失敗。。。");
}
public static void run(){
try{
procces(false, "A");
procces(true, "B");
procces(false, "C");
}catch(Exception ex){
System.out.println("処理 D 実行");
return;
}
throw new RuntimeException("全部失敗したよ!");
}
public static void main(String[] args) {
run();
}
}
@tokiwoousaka
Copy link
Author

正直すまんかった。

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