[
https://issues.apache.org/jira/browse/NET-278?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12743108#action_12743108
]
Theuns Cloete edited comment on NET-278 at 8/14/09 12:09 AM:
-------------------------------------------------------------
Rory, we do not have to swallow the exception, we could also make use of only a
try-finally:
public void disconnect() throws IOException
{
try {
if (_socket_ != null) _socket_.close();
if (_input_ != null) _input_.close();
if (_output_ != null) _output_.close();
}
finally {
_socket_ = null;
_input_ = null;
_output_ = null;
}
}
This way, the member variables will be assigned to null and the exception will
be thrown. But if _socket_.close() breaks first, there will not be a chance to
close _input_ and _output_. But will it even be possible to close _input_ and
_output_ if the _socket_ is broken?
was (Author: theuns.cloete):
Rory, we do not have to swallow the exception, we could make use of only a
try-finally:
public void disconnect() throws IOException
{
try {
if (_socket_ != null) _socket_.close();
if (_input_ != null) _input_.close();
if (_output_ != null) _output_.close();
}
finally {
_socket_ = null;
_input_ = null;
_output_ = null;
}
}
> FTPClient.disconnect() shouldn't throw IOException
> --------------------------------------------------
>
> Key: NET-278
> URL: https://issues.apache.org/jira/browse/NET-278
> Project: Commons Net
> Issue Type: Improvement
> Affects Versions: 2.0
> Environment: All
> Reporter: Raffaele Sgarro
> Priority: Minor
> Fix For: 3.0
>
> Original Estimate: 0.08h
> Remaining Estimate: 0.08h
>
> FTPClient.disconnect() shouldn't throw IOExceptions because it is typically
> placed in a finally block and it doesn't make much sense to
> try {
> client.disconnect()
> } catch (IOException e) {
> // You can't actually do anything
> }
> What is the purpose of such an exception if nobody can use it? There's
> nothing we can do if the client couldn't disconnect... You always usa a catch
> block with a /*do nothing*/ in your samples, so I think it's only an elegant
> thing to have a try block in a finally block...
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.