try catch块需要调用什么包么
我找抄书上的程序时InterruptedException 老显示错误
不懂

解决方案 »

  1.   

    程序如下
    package y01;
    public class j01 {
    public static void main(String args[]){
    Thread t=Thread.currentThread();
    System.out.println("cccc"+t);
    t.setName("my gad");
    System.out.println("dddd"+t);
    try{
    for (int i;i>0;i--){
    System.out.println(i);
    Thread.sleep(1000);
    }
    }catch (InerruptedException e){
    System.out.println("main");
    }
    }
    }
      

  2.   

    InerruptedException
    --------------
    拼错了:
    InterruptedException
      

  3.   

    for (int i;i>0;i--){
    -------------------------
    i应该初始化:
    for (int i=0;i>0;i--){
      

  4.   

    InerruptedException拼写错误啦!
    应该是InterruptedException
      

  5.   

    那此东西让工具们自动生成吧.自己手写时,直接CATCH  EXCEPTION
      

  6.   

    楼上的这个方法不是很好。你直接抓异常的顶级父类,系统开销会非常大。因为根据Java的异常处理机制的实现来看,它会在异常产生的时候逐步向栈的底部寻找,一直到找到对应的或者大于它的处理方法。你这样写似乎是把所有异常一把抓了,但是这样的内存占用也是非常大的。要在火车站抓人,不知道男女老少的去抓了来比对再判断快还是按图索骥的快?