class NestTry { public static void main(String args[]){ try{ int a = args.length; int b - 42 / a; System.out.println("a=a" + a); try{ if (a == 1) a = a / (a - a); if (a == 2) { int c[] = {1}; c[42] = 99; } } catch(ArrayIndexOutOfBoundException e) { System.out.println("ИндСкс Π·Π° ΠΏΡ€Π΅Π΄Π΅Π»Π°ΠΌΠΈ массива: " + e); } } catch(ArithmeticException e) { System.out.println("Π”Π΅Π»Π΅Π½ΠΈΠ΅ Π½Π° Π½ΡƒΠ»ΡŒ: " + e); } } } 

QUESTION 1:
What does code mean?

 if (a == 1) a = a / (a - a)? if (a == 2)? 

What is a = a / (a - a)? Каким ΠΎΠ±Ρ€Π°Π·ΠΎΠΌ a относится ΠΊ prescribed for a = a / (a - a)? Каким ΠΎΠ±Ρ€Π°Π·ΠΎΠΌ a относится ΠΊ a = a / (a - a)? Каким ΠΎΠ±Ρ€Π°Π·ΠΎΠΌ a относится ΠΊ s , вСдь c `is an array?

 int c[] = {1}; c[42] = 99; 

QUESTION 2:
What is the difference between throw and throws ?

QUESTION 3:
for which we write in this code again throw new IllegalAccessException("дСмонстрация"); ?

 class ThrowsDemo{ static void throwOne() throws IllegalAccessException { System.out.println(" Π’ Ρ‚Π΅Π»Π΅ ΠΌΠ΅Ρ‚ΠΎΠ΄Π° throwOne(al)."); throw new IllegalAccessException("дСмонстрация"); } public static void main(String args[]{ try{ throwOne(); } catch(IllegalAccessException e) { System.out.pritln("ΠŸΠ΅Ρ€Π΅Ρ…Π²Π°Ρ‡Π΅Π½ΠΎ ΠΈΡΠΊΠ»ΡŽΡ‡Π΅Π½ΠΈΠ΅: " + e); } } } 

    1 answer 1

    What is a = a / (aa) prescribed for?

    obviously, to intentionally generate an exception when dividing by zero. Given that a is of type int, subtraction of aa will result in a zero, which will lead to an exceptional situation when dividing.

    What is the difference between throw and throws?

    throw throws an exception, and throws says that the method to which it refers can throw such an exception without processing it inside. That is, throws throws nothing away, but only signals this, forcing the developer to handle this method accordingly.

    for which we write in this code again throw new IllegalAccessException ("demonstration")

    there is no re-emission exception. There are throws that report that a method can throw this exception and throw new IllegalAccessException ("demo") that throws it.

    • Do I understand correctly, throw - handles and throws an exception, and throws warns that there may be such an exception, the exception does not handle, throws it. - Seona16
    • 3
      no, wrong. throw throws an exception, but does not handle it. For processing, there is a catch block of try-catch-finally. throws does not throw an exception, but only declares that the method can throw it away - DreamChild
    • Thank you, everything is clear !!!! - Seona16
    • @ Ya16 since everything is clear, support the author by answering the answer as the right decision by clicking on the green check mark - dirkgntly
    • Tell me if I just want to warn that a method can be thrown out, we write class ThrowsDemo {static void throwOne () throws IllegalAccessException {System.out.println ("In the body of the method throwOne (al)."); - Seona16