Skip to content

Commit 38d22a1

Browse files
committed
README.md
1 parent b17dc29 commit 38d22a1

File tree

7 files changed

+36
-33
lines changed

7 files changed

+36
-33
lines changed

README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
2+
<h2>Visão Geral</h2>
3+
<ul>
4+
<li> Exceção é um evento que interrompe o fluxo normal de processamento de uma classe.
5+
</li>
6+
<li> O uso correto de exceções torna o programa mais robusto e confiável.
7+
</li>
8+
<li>Com o tratamento de exceções, um programa pode continuar executando depois de lidar com um problema.
9+
</li>
10+
<li><em>Importante:</em> Incorpore sua estratégia de tratamento de exceções no sistema desde o princípio do processo de projeto. Pode ser difícil incluir um tratamento de exceções eficiente depois que um sistema foi implementado.
11+
</li>
12+
</ul>
13+
14+
<div align="center">
15+
<figure>
16+
<img src="https://i.ibb.co/28mC8gY/2021-09-30-09-28.png" alt="2021-09-30-09-28" border="0" width="600" height="400">
17+
<figcaption>Hierarquia Exceptions em Java</figcaption>
18+
</figure>
19+
</div>
Binary file not shown.
Binary file not shown.
Binary file not shown.

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

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,14 @@
55

66
//Imprimir um arquivo no console.
77
public class CheckedException {
8-
public static void main(String[] args) {
8+
/*public static void main(String[] args) {
99
String nomeDoArquivo = "romances-blake-crouch.txt";
10-
try {
11-
imprimirArquivoNoConsole(nomeDoArquivo);
12-
} catch (FileNotFoundException exception){
13-
JOptionPane.showMessageDialog(null,"O arquivo não existe!");
14-
exception.printStackTrace();
15-
} catch (IOException e) {
16-
JOptionPane.showMessageDialog(null,"Ocorreu um erro não esperado!");
17-
e.printStackTrace();
18-
}
10+
imprimirArquivoNoConsole(nomeDoArquivo);
1911
2012
System.out.println("Apesar da exception ou não, o programa continua...");
2113
}
2214
23-
public static void imprimirArquivoNoConsole(String nomeDoArquivo) throws IOException {
15+
public static void imprimirArquivoNoConsole(String nomeDoArquivo) {
2416
File file = new File(nomeDoArquivo);
2517
2618
@@ -36,5 +28,5 @@ public static void imprimirArquivoNoConsole(String nomeDoArquivo) throws IOExcep
3628
} while(line != null);
3729
bw.flush();
3830
br.close();
39-
}
31+
}*/
4032
}

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,17 @@
44
import java.io.*;
55

66
public class ExceptionCustomizada_1 {
7-
public static void main(String[] args) {
8-
7+
/*public static void main(String[] args) {
98
String nomeDoArquivo = "romances-blake-crouch.txt";
109
imprimeArquivoNoConsole(nomeDoArquivo);
1110
System.out.println("Vai chegar nessa linha independente de qualquer coisa!");
1211
}
1312
1413
private static void imprimeArquivoNoConsole(String nomeDoArquivo) {
1514
File file = new File(nomeDoArquivo);
16-
try(BufferedReader br = new BufferedReader(new FileReader(file.getName()))) {
15+
16+
try{
17+
BufferedReader br = lerArquivo(file.getName());
1718
String line = br.readLine();
1819
1920
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
@@ -31,4 +32,9 @@ private static void imprimeArquivoNoConsole(String nomeDoArquivo) {
3132
e.printStackTrace();
3233
}
3334
}
35+
36+
private static BufferedReader lerArquivo(String nomeDoArquivo) {
37+
return new BufferedReader(new FileReader(nomeDoArquivo));
38+
}*/
39+
3440
}

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

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,11 @@
55
//Fazer a divisão de 2 valores inteiros
66
public class UncheckedException {
77
public static void main(String[] args) {
8+
String a = JOptionPane.showInputDialog("Numerador: ");
9+
String b = JOptionPane.showInputDialog("Denominador: ");
810

9-
boolean continuaLooping = true;
10-
do {
11-
String a = JOptionPane.showInputDialog("Numerador: ");
12-
String b = JOptionPane.showInputDialog("Denominador: ");
13-
14-
try {
15-
int resultado = dividir(Integer.parseInt(a), Integer.parseInt(b));
16-
System.out.println("Resultado: " + resultado);
17-
continuaLooping = false;
18-
} catch (ArithmeticException ex) {
19-
JOptionPane.showMessageDialog(null, "Divisão impossível! " + ex.getMessage());
20-
ex.printStackTrace();
21-
} finally {
22-
System.out.println("Chegou no finally!");
23-
}
24-
} while(continuaLooping);
25-
26-
System.out.println("O programa continua independente de exception!");
11+
int resultado = dividir(Integer.parseInt(a), Integer.parseInt(b));
12+
System.out.println("Resultado: " + resultado);
2713
}
2814

2915
public static int dividir(int a, int b) {

0 commit comments

Comments
 (0)