> 其他 >
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的用法
人气:466 ℃ 时间: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...
推荐
猜你喜欢
© 2026 79432.Com All Rights Reserved.
电脑版|手机版