您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

Java 实例 - 使用 catch 处理异常

2025/11/7 21:20:04发布22次查看
以下实例演示了使用 catch 来处理异常的方法:
/* author by w3cschool.cc main.java */ public class main{ public static void main (string args[]) { int array[]={20,20,40}; int num1=15,num2=10; int result=10; try{ result = num1/num2; system.out.println("结果为 " +result); for(int i =5;i >=0; i--) { system.out.println ("数组的元素值为 " +array[i]); } } catch (exception e) { system.out.println("触发异常 : "+e); } } }
以上代码运行输出结果为:
结果为 1 触发异常 : java.lang.arrayindexoutofboundsexception: 5
以上就是java 实例 - 使用 catch 处理异常的内容。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product