The way the code is written I thought I was meeting the requirements:
-calling all three methods in the handleExceptions method
-using only one try catch block
-printout out of the exceptions
Not sure what else could I am missing.
Please advise.
package com.codegym.task.task09.task0917;
/*
Catching unchecked exceptions
*/
public class Solution {
public static void main(String[] args) {
handleExceptions(new Solution());
}
public static void handleExceptions(Solution obj) {
obj.method1();
obj.method2();
obj.method3();
try
{
obj.method1();
obj.method2();
obj.method3();
}
catch (RuntimeException r)
{
printStack(r);
}
}
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();
}
}