Forum Stats

  • 3,734,722 Users
  • 2,247,033 Discussions
  • 7,857,471 Comments

Discussions

Question regarding catching multiple exceptions

Hi,

I thought this would be valid, catch multiple exceptions and throw the same again as below.

Did I do anything wrong here?

public class debug {

        public static void main(String[] argvs) {

            int abc = 123;

            try {

                int def = 0;

               

                def= abc / 0;

               

                int[] a = new int[2];

                for (int i = 1; i <= a.length; i++) {

                    a[i] = i;

                    System.out.println(i);

                }

            }

            catch (ArrayIndexOutOfBoundsException | ArithmeticException ex) {

                throw ex;

                //System.out.println("It doesn't work");

            }

            catch (Exception ex) {

                System.out.println("It works!!");

            }

        }

    }

Tagged:
This discussion has been closed.