请问一下,在重写一个线程类的run方法时,此run方法调用其它类的一个抛出异常的方法,此run方法不处理,也外上一级调用抛出,请问怎么完成些处理啊。我在重写run的时候采用throws Exception,可是编译时出错。
下面是我重写的run();此时由于throws PdmError,Exception会导致出错;public  void run() throws PdmError,Exception{
   try{
     new OpenFile().openfile(selectNode,iHistoryCopyVersion);
     //此openfile()可能抛出异常,并不处理,此时run要处理该异常,
     //捕捉到以后,继续向处抛出;
   }
   catch(PdmError e){
      throw e;
   }
   catch(Exception e1){
      throw e1;
   }}请问高手有何方法处理;急。

解决方案 »

  1.   

    线程已经不存在父亲类了,你让谁处理?所以线程中run方法中不能抛出非RuntimeException异常
      

  2.   

    让调用此线程run()的类处理啊。
      

  3.   

    没有一个类会调用 这个线程的run方法,最多只有一个类调用它的start方法例如:一个类A中
    public void methodA() {
      myThread.start();
    }但是你要注意,在调用start之后,methodA已经退出了,也就是你的线程的run方法出现异常的时候,外面的程序早退出了methodA去了,谁捕获这个异常???
    PS:你不会告诉我,你调用的是myThread.run()吧?这样只是执行一个方法,不是启动一个线程!
      

  4.   

    将捕获到的Exception封装成一个RuntimeException再抛出。public  void run() throws PdmError,Exception{
       try{
         new OpenFile().openfile(selectNode,iHistoryCopyVersion);
         //此openfile()可能抛出异常,并不处理,此时run要处理该异常,
         //捕捉到以后,继续向处抛出;
       }
       catch(PdmError e){
          throw new RuntimeException(e.getMessage(), e);
       }
       catch(Exception e1){
          throw new RuntimeException(e.getMessage(), e1);
       }
    }
      

  5.   

    将捕获到的Exception封装成一个RuntimeException再抛出。public  void run() throws PdmError,Exception{
       try{
         new OpenFile().openfile(selectNode,iHistoryCopyVersion);
         //此openfile()可能抛出异常,并不处理,此时run要处理该异常,
         //捕捉到以后,继续向处抛出;
       }
       catch(PdmError e){
          throw new RuntimeException(e.getMessage(), e);
       }
       catch(Exception e1){
          throw new RuntimeException(e1.getMessage(), e1);
       }
    }