现在的位置: 首页 > 综合 > 正文

Java exception

2013年08月20日 ⁄ 综合 ⁄ 共 1080字 ⁄ 字号 评论关闭

 

Java exception :

 

package com;

public class Test {

    
public static void main(String[] args) {

    
try {
        
throw new NullPointerException();
        
//System.out.println("Exception:"); // unreachable
    }
 catch (NullPointerException ex) {
        System.
out.println("Exception:");
        System.
out.println(ex.getMessage());
    }


    
try {
        exceptionOne();
    }
 catch (NullPointerException ex) {
        System.
out.println("exceptionOne:");
        System.
out.println(ex.getMessage());
    }


    
try {
        exceptionTwo();
    }
 catch (NullPointerException ex) {
        System.
out.println("exceptionTwo:");
        System.
out.println(ex.getMessage());
    }


    
// exceptionOne(); // exit main and program terminate

    }


    
private static void exceptionOne() {
    
throw new NullPointerException();
    
//System.out.println("Exception:"); // unreachable
    }


    
private static void exceptionTwo() {
    
if (true{
        System.
out.println("ex2");
        
throw new NullPointerException();
    }

    }

}

 

Exception:
null
exceptionOne:
null
ex2
exceptionTwo:
null

抱歉!评论已关闭.