commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jeff Duska <>
Subject [Net] FTPClient and finally questions...
Date Tue, 22 Jul 2003 22:12:09 GMT
I am very confused. I'm moving my code base from the enterprisedt
library to use the Jakarta Commons Net library. I have it downloading
files like a charm. Today, I was writing up a few simple jUnit tests to
make sure the exceptions for no files and connection timeout worked.
I've been having problems all day. Here is a section of code from my
getFiles() method.

    _files = ftpClient.listNames(mask);

            if (_files == null || _files.length ==0) {
                log.warn("No files to download for mask " + mask);
                throw new FTPServerException("No files found!");

        // code to download the files

        } catch (IOException e) {
            String msg = "FTP Server Error Occurred" +
            throw new FTPServerException(msg);
        } finally {
            if (ftpClient.isConnected()) {
                try {
                } catch (IOException f) {
                    // do nothing
            return _files;

I throw a FTPServerException when listNames returns a zero length array
or null. The problem is my FTPServerException is getting lost.  I can
follow the exception into the finally cause. Once I return from this
method, java forgets about my exception that I threw. In my example unit
test, shown below, I don't get a FTPServerException thus my test fails.

  public void testFileDownloadFailure() throws FTPServerTimeoutException
        try {
            // setup will creates an instance of FTPServer
            // FTP server should cause a FTPServerException
            _ftp.getFiles("myfile", ".");
        } catch (FTPServerException  e) {
            // do nothing, we expect this to happen

It seems like the finally cause is somehow "eating" my exception, yet
there is no other exception being raised. Does anyone see why this is

I copied the example pretty much out of the JavaDocs and the example file. I looked at the InformIT article. This example doesn't
bother to disconnect if there is a problem. I would think that this
would cause the system to leak network resources,  or will the the
garbage collection free up these resources. If this isn't an issue, I
could just remove the finally cause. Actually, I'm going to do this as
work-around, but I'd still like to know why finally cause isn't working.

Thanks for the help,

Jeff Duska

View raw message