Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6474895

Should support multiple exceptions in a catch block

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Duplicate
    • Icon: P5 P5
    • None
    • 6
    • specification
    • x86
    • windows_xp

      A DESCRIPTION OF THE REQUEST :
      Java does not allow me to catch exceptions looks like following:

      try{
          object.method();
      } catch (Exception1, Exception2 e) {
          System.out.println ("You should check the DEVICE_1");
      } catch (Exception3, Exception4 e) {
           System.out.println ("You should check the DEVICE_2");
      }

      JUSTIFICATION :
      Sometime, I want to deal some exceptions with the same behaviour. At the current, I have to deal each exception with a catch block. For instance:

      try{
          object.method();
      } catch (Exception1 e) {
          System.out.println ("You should check the DEVICE_1");
      } catch (Exception2 e) {
          System.out.println ("You should check the DEVICE_1");
      } catch (Exception3 e) {
           System.out.println ("You should check the DEVICE_2");
      } catch (Exception4 e) {
          System.out.println ("You should check the DEVICE_2");
      }

      I do the same behaviour with Exception1 and Exception2, and other the same behaviour with Exception3 and Exception4, but I have to declare 4 catch statement.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      It will be great if I can write code as described in the Description part.

            iris Iris Clark
            gmanwanisunw Girish Manwani (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: