第05章--异常处理(信息学院2014级).pptVIP

  • 3
  • 0
  • 约1.1万字
  • 约 41页
  • 2017-11-27 发布于贵州
  • 举报
第05章--异常处理(信息学院2014级)

6. try-catch语句的范围 try-catch目的是为了程序能从异常中恢复过来; 需要对有可能产生异常的语句定位,并使用try-catch,而不是把所有语句都包起来 * public class TryScope { public static void main(String[] args) { String[] strings = { 32, one, 10.8, 45 }; float sum = 0; try { for (String s : strings) sum += Integer.parseInt(s); System.out.println(sum = + sum); } catch (Exception e) { e.printStackTrace(); } } } 武汉理工大学信息学院《Java程序设计实用教程(第4版)》 Try catch范围举例 * 能否正确输出87.8呢? 武汉理工大学信息学院《Java程序设计实用教程(第4版)》 5.2.2 抛出异常 1. 抛出自定义异常对象的throw语句 throw 异常对象 public void set(int year, int month, int day) { if (month1 || month12) t

文档评论(0)

1亿VIP精品文档

相关文档