mina-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Andrea Francia" <and...@andreafrancia.it>
Subject Re: Exceptions of the FileSystemView
Date Thu, 02 Oct 2008 10:13:03 GMT
2008/10/2 Niklas Gustavsson <niklas@protocol7.com>:
> On Wed, Oct 1, 2008 at 11:29 PM, Andrea Francia <andrea@andreafrancia.it> wrote:
>> Here the FileSystemView interface declaration:
>> public interface FileSystemView {
>>   FileObject getHomeDirectory() throws FtpException;
>>   FileObject getCurrentDirectory() throws FtpException;
>>   boolean changeDirectory(String dir) throws FtpException;
>>   FileObject getFileObject(String file) throws FtpException;
>>   boolean isRandomAccessible() throws FtpException;
>>   void dispose();
>> }
>> Why we use a generic FtpException while, I think, an IOException will
>> describe more precisely the type of the problem that can happen?
> Our exception strategy would definitely benefit from some love. In
> this specific case, I'm not sure what's the best thing to do. Remember
> that a file system can be backed by all sorts of technology, for
> example, JDBC seems like a common choice. Is IOException a good fit if
> something goes wrong within JDBC (which itself would throw a
> SQLExeption) or JMS (which throws a JMSException)?

But all these exception are about the (virtual) file system.
My FTPServerStub uses a virtual filesystem that exists only in memory.
The virtual file system is implemented using Maps, and Lists. When the
user access to an non existent (virtual) file the code raise an
FileNotFoundException (that extends IOException), not the

If your filesystem layer is backed by a database and you cannot
retrieve the file data because the link with the database has
disappeared this is an I/O problem. You can always use the exception
chaining with the JDBCException. When I use the standard library
java.io APIs to access a File that resides on a network disk not yet
available I receive an IOException, to a net exception.

The filesystem layer backed by a database is emultating a filesytem,
java.io has a nice collection of various type of Exception that cover
many failure cases:

 - ClosedChannelException,
 - EOFException,
 - FileLockInterruptionException,
 - FileNotFoundException,
 - IIOException,
 - InterruptedIOException,

If there is a problem with the JDBC link you can always use exception chaining.

public FileObject getFile(String path) throws IOException {
   try {
      FileObject result = retrieveFromDB() {
   } catch(SQLExeption cause) {
      IOException ex = IOException("Unable to connet to DB");
      throw ex;

Note that the case where the the link with the DB is ok but the
request file doesn't exist on the database could be covered simply

 private FileObject retrieveFromDB()
     throws SQLExeption , // when there are problem to link with the DB
               FileNotFoundException // when the file does not exist

The FtpException are to broad, the FtpServer can fail for so many
aspect, problem with the filesystem, problem with the userManagers,

Andrea Francia

View raw message