今回は、例外処理―想定外のエラーへの対処―です。
 Javaでは、ときどき例外処理を書かないといけないケースがあります。
 書き方は難しくないので、覚えちゃいましょう。
■動画はこちら
■Youtube版の解説で使用しているソースコード
 動画と一緒にこちらも参考にどうぞ。
1.例外処理ありの割り算
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | public class ExceptionTest {     public static void main(String[] args) {         try {             int a = 5;             int b = 0;             //0で割り算(ここで例外が発生)             int c = a / b;             System.out.println(c);         } catch(Exception e) {             //割り算に失敗             System.out.println("割り算に失敗しました。");         } finally {             //処理の終了を表示             System.out.println("処理を終了しました。");         }     } } | 
2.例外処理なしの割り算
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | public class ExceptionTest2 {     public static void main(String[] args) {         int a = 5;         int b = 0;         //0で割り算(ここで例外が発生)         int c = a / b;         System.out.println(c);         //処理の終了を表示         System.out.println("処理を終了しました。");     } } | 














