Theme try/catch/exceptions is not dificoult so why I can't understand what I should to do in this task?
My code is OK but not acceptable.
I should catch all exceptions without Null, Index and Number?
package com.codegym.task.task09.task0917;
/*
Catching unchecked exceptions
*/
public class Solution {
public static void main(String[] args)
{
try {
handleExceptions(new Solution());
}
catch (NullPointerException | IndexOutOfBoundsException | NumberFormatException e) {
printStack(e);
}
}
public static void handleExceptions(Solution obj) {
obj.method1();
obj.method2();
obj.method3();
}
public static void printStack(Throwable throwable) {
System.out.println(throwable);
for (StackTraceElement element : throwable.getStackTrace()) {
System.out.println(element);
}
}
public void method1() {
throw new NullPointerException();
}
public void method2() {
throw new IndexOutOfBoundsException();
}
public void method3() {
throw new NumberFormatException();
}
}