首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

让人吃惊的java exception错误

2012-08-27 
让人吃惊的java exception异常今天在看一段源码的时候,遇到关于异常的奇怪问题下面给出源码,大家在不运行

让人吃惊的java exception异常
    今天在看一段源码的时候,遇到关于异常的奇怪问题下面给出源码,大家在不运行的前提下如果能给出运行结果,那么你就是异常牛人了:
     第一种情况:
      public static void main(String[] args) {
int i = 8/0;
System.out.println("this is last step~@");
     }
     运行结果:
     第二种情况:
      public static void main(String[] args) {
try {
     int i = 8/0;
} catch (ArithmeticException e) {
     e.printStackTrace();
}
System.out.println("this is last step~@");    
     }
     运行结果:
    第三种情况:
      public static void main(String[] args) {
try {
     Class.forName("anyclassname");
} catch (ClassNotFoundException e) {
     e.printStackTrace();
}
System.out.println("this is last step~@");    
     }
     运行结果:
     上面的运行结果会很好的帮助你理解Exception和RuntimeExpcetion两种的却别,这也是面试时经常遇到的一个问题,希望对您有帮助 1 楼 lingqi1818 2012-03-13   JAVA中异常处理的好坏决定你的代码是恶心还是美观,哈哈。

热点排行