尝试没有Catch Error

时间:2015-11-25 01:57:02

标签: java compiler-errors try-catch

我正在编写一个程序来处理序列化文件。我收到错误,说我的openObjectInputStreamMethod中有一个没有catch的try。问题是我在这个方法中尝试和捕获。其他一切似乎都很好。任何帮助都会很棒。

  public static ObjectInputStream openObjectInputStream( String fileName )
    throws IOException
  {
    /*
     *  This is a generic open method for an ObjectInputStream.
     *  Using the received String value (containing a file name), this method should
     *    create a new ObjectInputStream and return the reference to the newly  
     *    instantiated ObjectInputStream to the calling method.
     */
    try
    {
      inAccount = new ObjectInputStream(
                                         Files.newInputStream(
                                                               Paths.get("NewAccounts.ser" ) ) ) ;
      return new ObjectInputStream  // complete this statement.

    }  // end try block
    catch( IOException openError )
    {
      System.err.printf( "%nError opening %s", fileName ); // output an alert
      // rethrow/chain exception to be caught in main
      throw new IOException( String.format( "Error opening %s", fileName ), openError );
    }
  }  // end openObjectInputStream


  public static void closeObjectInputStream( ObjectInputStream ObjInStream )
  {
    /*
     *  This is a generic close method for an ObjectInputStream.
     *  Using the instantiated ObjectInputStream object, this method will close that object 
     */
    try
    {
      // The ObjectInputStream object will be null only if it was never successfully opened
      if ( ObjInStream != null )                     
        ObjInStream.close();
    }
    catch( IOException closeError )
    {
      System.err.printf( "%nError closing %s", ObjInStream );
    }
  }  // end closeObjectInputStream

1 个答案:

答案 0 :(得分:1)

以下行缺少分号(即使这样也不正确):

return new ObjectInputStream  // complete this statement.

无法看到代码的其余部分,也许应该是:

return inAccount;  // complete this statement.