您的位置:首页 > 编程语言 > Java开发

Java exception

2008-05-26 20:32 190 查看
 

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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  exception java string null