各位大虾:我的A.java代码如下:
      import com.abc.*;
      ...others
      try
      {
        ...
        myfunc(it);
      }catch(Exception e)
      {
         do something here 
      }    其中myfunc()方法是com.abc.Test类的一个方法:
     myfunc(int i)
    {
       try
      {
      }catch(IOException ex)
      {
        System.out.println("myfunc is wrong");
      }     }
    请问:如果在A.java里执行myfunc()方法时出现异常,A.java能捕获吗?如何做?
    谢谢

解决方案 »

  1.   

    不能catch要想catch住必须在 myfunc(int i)
    中重新throw
      

  2.   

    这样做:
    myfunc(int i) throws IOException
    {}
    或:
    myfunc(int i) throws IOException
    {
    try
    {
    }catch(IOException ex)
    {
    System.out.println("myfunc is wrong");
    throw ex;
    }
    }
      

  3.   

    谢谢答复
    to polarman(北极人http://blog.csdn.net/polarman) :
       myfunc(int i) throws IOException后,在a.java能捕获这个ioexception吗?
      

  4.   

    myfunc 中throws出去A.java就能捕获
      

  5.   

    我试过,让myfunc() throws Exception
    可是当myfunc发生异常时,A.java没能捕获
    不知道如何
      

  6.   

    在myfunc中已经捕获了
    修改:
     myfunc(int i) throws Exception
        {
           try
          {
          }catch(IOException ex)
          {
            System.out.println("myfunc is wrong");
            throw new Exception();
          }     }
      

  7.   

    只是需要将 Exception 重新抛出而已.
      

  8.   

    如果异常需要在catch后重新被throw出去,那你又何必catch呢?