I feel the code the working fine. All exceptions are caught but the validation is not going through. Please help.
package com.codegym.task.task09.task0914;
/*
Catching a group of exceptions
*/
public class Solution {
public static void main(String[] args) throws Exception {
try {//write your code here
method1();
}
catch (Exception3 e)
{
System.out.println("Exception3 : caught"+ e.getClass());//write your code here
}
catch (Exception2 e)
{
System.out.println("Exception2 : "+ new Exception2("Exception2 caught"));//write your code here
}
catch (Exception1 e)
{
System.out.println("Exception1 : "+ new Exception3("Exception3 caught"));//write your code here
}
}
public static void method1() throws Exception1, Exception2, Exception3 {
int i = (int) (Math.random() * 3);
if (i == 0)
throw new Exception1("Exception1");
if (i == 1)
throw new Exception2("Exception2");
if (i == 2)
throw new Exception3("Exception3");
}
}
class Exception1 extends Exception {
public Exception1(String message)
{
super(message);
}
}
class Exception2 extends Exception1 {
public Exception2(String message)
{
super(message);
}
}
class Exception3 extends Exception2 {
public Exception3(String message)
{
super(message);
}
}