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