[jcifs] SmbException Supercedes boolean?

Rob Wygand rob at wygand.com
Tue Oct 30 08:24:37 EST 2001


James,

The argument for exceptions being thrown was made a long time ago. I'm 
still not sure which is the 100% right approach, but there needed be be 
some mechanism whereby the reason the operation failed could be 
determined.  If I cannot create a new file because of a network failure, 
a permissions issue, or the disk is full, I might need to do that, and 
just a boolean return value doesn't do it.  Exceptions do. I've talked 
before about having some other mechanism (such as an some sort of error 
handler class), but Mike seemed set on Exceptions.

rjw

James Nord wrote:

> Well I would go the other way and return boolean...
> 
> Better design as exceptions should not be used to test if an opperation 
> was succesfull...
> Makes for cleaner code/programming structure (if used correctly)
> (IMHO which goes 100% against the other reply ;-) )
> 
> Also - its what the java libraries do...
> 
> mkdir()
>    public abstract boolean mkdir()
>    Creates a directory, the pathname of which is specified by this
>    XFileAccessor object.
> Returns true if the directory could be created; false otherwise.
> 
> 
> Just my religion...
> 
> Besides, does it harm to return boolean? It may come a time where its 
> benifical to the code.
> Is it not possible to not make a directory/file etc.. and not throw a 
> exception?
> What about isDirectory() ???
> That *must* return boolean and possibly throw an exception?
> 
> /James
> 
> Rob Wygand wrote:
> 
>> Mike,
>>
>> I recently encountered this, and I think it's best to return void.  We 
>> had some functions that returned boolean, but always threw exceptions 
>> on errors, and what we found was that some people caught the 
>> exceptions and did nothing with them, only using the return value of 
>> the function. This, obviously, caused confusion and errors. It's just 
>> a much clearer contract when void is returned.
>>
>> rjw
>>
>> Allen, Michael B (RSCH) wrote:
>>
>>> Does anyone have an opinion as to whether or not SmbFile methods should
>>> return boolean now that many throw SmbException? For example, 0.5.1 has:
>>>
>>> public boolean mkdir()
>>>
>>> which looks like it's java.io.File counterpart and returns true if 
>>> the directory was
>>> successfully created and false otherwise. For 0.6.0 I was planning on 
>>> just
>>> adding the throws to this like:
>>>
>>> public boolean mkdir() throws SmbException
>>>
>>> but returning boolean is rather pointless given that any kind of 
>>> failure provokes
>>> an SmbException. I don't know of any other context that might make 
>>> use of
>>> boolean. I think this should just be:
>>>
>>> public void mkdir() throws SmbException
>>>
>>> Any opinions? Obviously this is pretty important because it's 
>>> undoubtledly
>>> going to break code so I'd rather only do this once.
>>>
>>> Mike
>>>
>>>
>>
>>
> 
> 
> 






More information about the jcifs mailing list