View Single Post
  #1 (permalink)  
Old 03-08-2008, 04:38 AM
desmond5 desmond5 is offline
Member
 
Join Date: Mar 2008
Posts: 2
desmond5 is on a distinguished road
Trouble with factory method - unhandled exception type Exception
Hi!

I have a simple factory method:

Code:
public final class ComputerFactory { public static Computer create(ComputerType type) throws Exception { switch(type) { case PC: return new CompPC(); case Mac: return new CompMac(); case Sparc: return new CompSparc(); case Itanium: return new CompItanium(); } throw new Exception("No such computer: " + type ); } }
ComputerType is a enum with 4 items in it (all listen in the switch block).

When I try to create new Computers in another class with the factory method I get an error says: unhandled exception type Excepton:

Code:
comps.add(ComputerFactory.create(ComputerType.PC));
What's wrong with the code ?

Best wishes, Desmond
Reply With Quote
Sponsored Links