I thought I executed previous suggestions correctly but apparently I did not understand.
Could somebody please explain to me what is wrong? Where I went wrong? How to fix it?
package com.codegym.task.task09.task0914;
/*
Catching a group of exceptions
*/
public class Solution
{
public static void main(String[] args) throws Exception
{
//write your code here
try
{
method1 ( );
}
//write your code here
catch (Exception3 e)
{
printStackTrace();
}
catch (Exception2 e)
{
printStackTrace();
}
catch (Exception1 e)
{
printStackTrace();
}
}
public static void method1() throws Exception1, Exception2, Exception3
{
int i = (int) (Math.random() * 3);
if (i == 0)
throw new Exception1();
if (i == 1)
throw new Exception2();
if (i == 2)
throw new Exception3();
}
class Exception1 extends Exception
{
}
class Exception2 extends Exception1
{
}
class Exception3 extends Exception2
{
}
}
/*
class Solution
{
public static void main( String args[] )
{
method1();
}
public status void method1()
{
try
{
int num1 = 5/0;
}
catch (Throwable e)
{
e.printStackTrace();
}
}
}
*/