第8章异常处理.ppt

第8章?异常处理 5.1 异常的概念 5.2 异常处理 5.3 自定义异常 8.1.1 什么是异常 异常指的是程序运行时出现的非正常情况 例8-1 测试异常 public class? testException? { ????? public static void main(String args[]) { ??????????int x=Integer.parseInt(args[0]); int y=Integer.parseInt(args[1]); System.out.println(x+y=+(x+y)); ?????? }??? ?}??? (1)正常运行示例: java testException 23 45 输出结果: x+y=68 (3)错误运行现象2,输入的命令行参数不是整数 例如:java testException 3 3.4 则在控制台将显示数字格式错误的异常信息: Exception in thread main java.lang.NumberFormatException: For input string: 3.4 at java.lang.NumberFormatException.forInputString(NumberFormat Exce

文档评论(0)

1亿VIP精品文档

相关文档