3 Replies Latest reply: Oct 7, 2008 5:43 PM by 843785 RSS

    Correct way to handle an exception in a constructor?

      Hi I was wondering if anyone could tell me if I implemented my code correctly. It compiles and runs fine, I'm just wondering if there is a more efficient or better way to do this.

           static Cabin cabinTest;
      public static void main(String[] args) 
                     cabinTest = new Cabin(5, 2, true);
                catch(Exception e)
                     System.out.println("Invalid Input");
      public Cabin (int cabinNumber, int rooms, boolean kitchen) throws Exception
                super("C" + cabinNumber, rooms==1 ? ONE_ROOM_RATE : TWO_ROOM_RATE, 
                       rooms==1? ONE_ROOM_GUESTS : TWO_ROOM_GUESTS);
                     this.rooms = rooms;
                     this.kitchen = kitchen;