The Design of Software (CLOSED)

A public forum for discussing the design of software, from the user interface to the code architecture. Now closed.

The "Design of Software" discussion group has been merged with the main Joel on Software discussion group.

The archives will remain online indefinitely.

Need help in naming a Java Method

I have an object called Processor, that has 2 public methods:

1. public void setTxn(Transaction theTransaction) throws ProcessorException
2. public void process() throw ProcessorException.

I now have a situation, where under certain situations, depending upon whethere the caller cares for the information of not, I want the process() to throw a second exception, which is ProcessorCommunicationException.

What is the best possible way impmement this?

Is it something like
public void process(boolean bReportCommunicationErrors) throws ProcessorException, ProcessorCommunicationException


is it
public void processAndReportCommunicationErrros() throws ProcessorException, ProcessorCommunicationException

or is it something else?

Wednesday, April 26, 2006
Uhh, why not just

public void process() throws ProcessorException, ProcessorCommunicationException

And have the caller swallow the exceptions you don't care about.
Wednesday, April 26, 2006
The caller can choose to ignore the errors.  If you encounter the error and you can't handle it, it needs to be passed up the stack.

Now, if the caller needs you to ignore the error and continue processing, that's a different story...
Caffeinated Send private email
Wednesday, April 26, 2006
You could also just have ProcessorCommunicationException descend from ProcessorException. This way your throws would just have ProcessorException in it and the client could look at the exception type they get back to decide if they want to do something specific depending on the exception. Of course, you would want to document this behavior in your javadoc.

This tends to be my preference with an existing API where I want to avoid breaking existing code that uses it when possible.
Gerald Send private email
Wednesday, April 26, 2006
What is with this method name!?!

public void setTxn(...

What is a Txn? How about public void setTransaction(...
Wednesday, April 26, 2006
Yeah, I thought it was funny that you abbreviated "Transaction" (a word which doesn't contain an "x") to "Txn", but then you suggest a method called processAndReportCommunicationErrors.
BenjiSmith Send private email
Wednesday, April 26, 2006
I hate Java checked exceptions. This is one of those cases that explains why 99% of the Java programmers in the world just code all of their methods either like this:

public void process() throws Exception

or like this:

public void process()
    catch (Exception ex)
        // Swallow the exception.

I personally prefer the former.
Monday, May 01, 2006
+1 to dave

Tx is a pretty common abbriviation for Transaction, so setTxn is readable, although setTransaction is better.

On the other hand, variables that start with "the" make me vomit. Doubly so if they're not classs variables.
Thursday, May 04, 2006

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics
Powered by FogBugz