当执行  
   cstObjects[0].customerName="Tom";
时,以下那种方法可防止异常中止程序运行结果
  a。try块写代码,catch中捕获NullPointerException异常
  b。把代码写在finally中
  c。try块写代码,finally中捕获NullPointerException异常
  d。throw抛异常,catch捕获此异常
 选择_______
为什么?

解决方案 »

  1.   

    a
    出现异常后,在catch中捕获并处理异常完成后,将继续执行try{}catch{}finally{}外的程序
      

  2.   

    搂住要多看看基础了
    class Test { public static void main(String[] args) {
    MyClass[] mc=null;
    try {
    mc[0].i = 7;//这里将抛出异常,try模块中后面的代码将不会被继续执行;程序跳转到catch中执行;
         System.out.println("hehe ,this is a test");
    } catch (NullPointerException ne) {
    ne.printStackTrace();//把捕获的异常信息打印出来
    }
    System.out.println("hehe ,hello world");//虽然前面产生了异常,但是由于被捕获,并处理了,所以这句代码能够执行的
    }
    }class MyClass {
    public int i;
    }
      

  3.   

    直接throw这个异常,这个说明你的程序不好出现NullPointerException
    在代码中从对象取值之前应该检查对象是否为空,发生这样的情况不好
    你可以专门作一个类或者方法来处理!啊哈!