public class Ex3{
public class Ex3{
int x;
public static void main(String ar[])throws Exception{
int y=0;
Ex3 c=new Ex3();
try{
y=3/c.x;
y=y+1;}catch(Exception e){
System.out.println("errors occur!");
System.out.println("getMessage="+e.getMessage());
System.out.println("toString="+e.toString());}
System.out.println("program ends ok");
System.out.println("the y is:"+y);
}
}
注释一下每行,不太懂try catch的用法
int x;
public static void main(String ar[])throws Exception{
int y=0;
Ex3 c=new Ex3();
try{
y=3/c.x;
y=y+1;}catch(Exception e){
System.out.println("errors occur!");
System.out.println("getMessage="+e.getMessage());
System.out.println("toString="+e.toString());}
System.out.println("program ends ok");
System.out.println("the y is:"+y);
}
}
注释一下每行,不太懂try catch的用法
其他人气:969 ℃时间:2020-05-10 12:45:29
优质解答
public class Ex3{ //类int x; public static void main(String ar[])throws Exception{ //主函数,//throws Exception是遇到异常抛出,如果其他类或函数用到可以用catch捕//捉到int y=0; Ex3 c=new Ex3(); try{ //在t...
我来回答
类似推荐
猜你喜欢
- 1过公司生产甲乙两种产品,
- 2全班有46人去划船,共乘12条船,其中大船坐5人,小船坐3人,每条船都刚好坐满,那么大 小船应是多少条全班有46人去划船,共乘12条船,其中大船坐5人,小船坐3人,每条船都刚好坐满,那么大 小船应是多少条
- 37个单数相加能不能等于30?
- 4如图,y=-5x+5与坐标轴交于A、B两点,△ABC为等腰直角三角形,双曲线y=k/x(x<0)过C点,求k的值.
- 5加入音乐俱乐部用英语怎么说
- 6为什么说场强方向是电势降落最快的方向
- 7小明妈妈买3千克苹果和4千克梨共用17元,小青妈妈买4千克梨和3千克苹果共用18元,每千克苹果和梨多少元?
- 8The ball games are so hard that we cannot play
- 9有5瓶白色固体试剂,分别是BaCl2,NaOH,NaCl,CuSO4,NaSO4.现在只提供蒸馏水,通过3个步骤鉴别他们?
- 10英语缩略词有哪些?