Skip to Main Content

Java Development Tools

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Question regarding catching multiple exceptions

jimmy437Apr 16 2014

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!!");

            }

        }

    }

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 14 2014
Added on Apr 16 2014
0 comments
723 views