/
GermanezZ
/
JavaExercises
Обзор
Документация
Войти
/
GermanezZ
/
JavaExercises
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
AllMetanitLessons/Exeptions/MySpecialExtendsException.java
44 строки
1 KB
germa
Уроки по Metanit
04 дек 2024, 20:39
04 дек 2024, 20:39
48d575a
Код
Авторство
О чём код?
package AllMetanitLessons.Exeptions; public class MySpecialExtendsException { public static void main(String[] args) { int[] arr1 = {1,2,3,4,5,6,7,8,9}; int[] arr2 = {0,2,3,4,50,4,0}; try { for (int i = 0; i < arr1.length; i++){ try { if (arr1[i]%arr2[i]!=0){ throw new NonIntResult(arr1[i],arr2[i]); } System.out.println("Result is: " + arr1[i]/arr2[i]); }catch (ArithmeticException exc){ System.out.println("Деление на ноль"); }catch (NonIntResult exc){ System.out.println(exc.toString()); } } }catch (ArrayIndexOutOfBoundsException exc){ System.out.println("Выход за пределы массива"); } } } class NonIntResult extends Exception{ private final int a,b; NonIntResult(int a,int b){ this.a =a; this.b = b; } @Override public String toString() { return "Result " + a + "/" + b + " is not integer" ; } }