Skip to content

Commit 85e5718

Browse files
Criando Exceção Customizada
1 parent a108eca commit 85e5718

File tree

2 files changed

+20
-9
lines changed

2 files changed

+20
-9
lines changed

.idea/misc.xml

Lines changed: 1 addition & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,39 @@
11
package br.com.dio.exceptions;
22

33
import javax.swing.*;
4+
import java.util.Arrays;
45

56
public class ExceptionCustomizada_2 {
67
public static void main(String[] args){
78
int[] numerador = {4, 5, 8, 10};
89
int[] denominador = {2, 4, 0, 2, 8};
910

11+
1012
for (int i = 0; i < denominador.length; i++) {
11-
try {
12-
if(numerador[i] %2 != 0)
13-
throw new DivisaoNaoExataException("Divisão não exata!", numerador[i], denominador[i]);
13+
try{
14+
if(denominador[i] == 0)
15+
throw new DivisaoPorZeroException("Divisao por Zero",denominador[i]);
16+
try {
17+
if (numerador[i] % denominador[i] != 0)
18+
throw new DivisaoNaoExataException("Divisão não exata!", numerador[i], denominador[i]);
19+
}catch(ArrayIndexOutOfBoundsException e){
20+
throw new TamanhoDoArrayInvalidoException("Tamanho do Array Invalido", i);
21+
}
1422

1523
int resultado = numerador[i] / denominador[i];
1624
System.out.println(resultado);
17-
} catch (DivisaoNaoExataException | ArithmeticException | ArrayIndexOutOfBoundsException e) {
18-
e.printStackTrace();
25+
26+
27+
} catch (DivisaoNaoExataException | DivisaoPorZeroException | TamanhoDoArrayInvalidoException e) {
28+
// e.printStackTrace();
1929
JOptionPane.showMessageDialog(null, e.getMessage());
2030
}
31+
32+
33+
2134
}
2235

36+
2337
System.out.println("O programa continua...");
2438
}
2539
}

0 commit comments

Comments
 (0)