Created
July 2, 2014 02:48
-
-
Save typosone/830ba372d6a9f9468d21 to your computer and use it in GitHub Desktop.
Java講義 サンプル (例外)
This file contains 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
import java.io.BufferedReader; | |
import java.io.FileReader; | |
import java.io.FileNotFoundException; | |
import java.io.IOException; | |
public class Cat { | |
public static void main(String...args) { | |
for (int i = 0; i < args.length; i++) { | |
System.out.println("ファイル名: " + args[i] + "===="); | |
try { | |
BufferedReader reader = | |
new BufferedReader(new FileReader(args[i])); | |
while (true) { | |
String line = reader.readLine(); | |
if (line == null) { | |
break; | |
} | |
System.out.println(line); | |
} | |
reader.close(); | |
} catch (FileNotFoundException e) { | |
System.out.println("ファイルが見つかりません: " + e); | |
} catch (IOException e) { | |
System.out.println("I/Oエラーです: " + e); | |
} | |
} | |
} | |
} |
This file contains 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 ExceptionTest1 { | |
public static void main(String...args) { | |
int[] array = new int[3]; | |
try { | |
System.out.println("代入します"); | |
//array[100] = 0; | |
array[0] = 0; | |
System.out.println("代入しました"); | |
} catch (ArrayIndexOutOfBoundsException e) { | |
System.out.println("代入できませんでした"); | |
System.out.println("例外は" + e + "です"); | |
} | |
System.out.println("終了します"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment