/*
*自定义异常类
*/
public class UnsupportedShapeException extends Exception{
private static final long serialVersionUID = 1L;
public UnsupportedShapeException(){
System.out.println("我的自定义异常类");
}
}
/*
*使用
*/
public class ShapeFactory {
public static Shape createShape(String shape) throws UnsupportedShapeException{
if(shape.equalsIgnoreCase("circle")){
System.out.println("producing circle....");
return new Circle();
}else if(shape.equalsIgnoreCase("rectangle")){
System.out.println("producing rectangle....");
return new Rectangle();
}else if(shape.equalsIgnoreCase("triangle")){
System.out.println("producing triangle....");
return new Triangle();
}else{
throw new UnsupportedShapeException();
}
}
}