Following on from [exception.message], if a method needs to be able to return multiple data items, the temptation is to write a new exception that has all the data in it, and throw the exception back to to the caller.

public void determineNextFileStatus() throws StatusException
    StatusException e = new StatusException();
    throw e;

Don't do it.  Exceptions are for exceptional circumstances only, and are only supposed to contain error data.  Note that in the above example, the developer used the vague word “determine” because their method threw an exception instead of returning anything.

Far better to split the method call in two or return a new object with many properties:

public FileStatus getNextFileStatus()
    FileStatus status = new FileStatus();
    return status;
blog comments powered by Disqus