码迷,mamicode.com
首页 > 其他好文 > 详细

实验九—抛出异常

时间:2019-05-27 00:49:17      阅读:166      评论:0      收藏:0      [点我收藏+]

标签:xtend   ||   http   rectangle   ring   point   图片   src   err   

package 实验包;
public class error {
 public static void main(String[] args) {
  point point1=new point(1,2);
  point point2=new point(1,2);
  point point3=new point(1,2);
  rectangle rectangle1=new rectangle(point1,0,0);
  triangle t=new triangle(point1,point2,point3);
  point pointx[]= new point[]{point1,point2};
  polygon polygonx=new polygon(pointx);
 }
}

class point{
 point(){}
 int x,y;
 public point(int x,int y)throws IllegalArgumentException
 {
  this.x=x;
  this.y=y;
  if(x<0||y<0){
   throw new IllegalArgumentException("抛出无效参数,异常");
  }
 }
}

class rectangle extends point{
 public rectangle(point point1,int length,int width)throws IllegalArgumentException
 {
  if(length<0||width<0){
   throw new IllegalArgumentException("抛出无效参数,异常");
  }
 }
}

class triangle extends point{
 public triangle(point point1,point point2,point point3)throws IllegalArgumentException
 {
  if((point1.x==point2.x)&&(point1.x==point3.x)&&(point1.y==point2.y)&&(point1.y==point3.y)){
   throw new IllegalArgumentException("抛出无效参数,异常");
  }
 }
}

class polygon extends point{  

public polygon(point[] points)throws IllegalArgumentException  {   

if(points.length<3){    

throw new IllegalArgumentException("抛出无效参数,异常");

  }  

}

}

技术图片

实验九—抛出异常

标签:xtend   ||   http   rectangle   ring   point   图片   src   err   

原文地址:https://www.cnblogs.com/zrwhaha/p/10928531.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!