Skip to content

Commit 4012911

Browse files
committed
CheckedException
1 parent 0d336a1 commit 4012911

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed
2.35 KB
Binary file not shown.

src/br/com/dio/exceptions/CheckedException.java

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,29 @@
55

66
//Imprimir um arquivo no console.
77
public class CheckedException {
8-
/*public static void main(String[] args) {
9-
String nomeDoArquivo = "romances-blake-crouch.txt";
10-
imprimirArquivoNoConsole(nomeDoArquivo);
8+
public static void main(String[] args) {
9+
String nomeDoArquivo = "romance-blake-crouch.txt";
10+
11+
try {
12+
imprimirArquivoNoConsole(nomeDoArquivo);
13+
} catch (FileNotFoundException e) {
14+
JOptionPane.showMessageDialog(null,
15+
"Revise o nome do arquivo que você deseja imprimir! " + e.getCause());
16+
e.printStackTrace();
17+
} catch (IOException e){
18+
//e.printStackTrace();
19+
JOptionPane.showMessageDialog(null,
20+
"Ocorreu um erro inesperado! Entre em contato com o suporte! " + e.getCause());
21+
} finally {
22+
System.out.println("Chegou no finally!");
23+
}
1124

1225
System.out.println("Apesar da exception ou não, o programa continua...");
1326
}
1427

15-
public static void imprimirArquivoNoConsole(String nomeDoArquivo) {
28+
public static void imprimirArquivoNoConsole(String nomeDoArquivo) throws IOException {
1629
File file = new File(nomeDoArquivo);
1730

18-
1931
BufferedReader br = new BufferedReader(new FileReader(file.getName()));
2032
String line = br.readLine();
2133

@@ -28,5 +40,5 @@ public static void imprimirArquivoNoConsole(String nomeDoArquivo) {
2840
} while(line != null);
2941
bw.flush();
3042
br.close();
31-
}*/
43+
}
3244
}

0 commit comments

Comments
 (0)