Originally posted by Aly Gilani:
But isnt it against good coding practices to avoid using "returns" in the middle of a method?
This is an outdated idea. What's bad is writing very long methods with confusing control flow. If you write a method with less than a dozen lines of code, there's absolutely nothing wrong with a return in the middle. But you can always invert the logic and execute the rest of the body inside the if, right?
And also we would end up with a lot of return statements if we are dealing with multiple params. Any other way to deal with it?
You should not throw an exception during normal execution. That means, for example, don't use an ArrayIndexOutOfBoundException to terminate a for loop.
If you need to report a programming error -- and a null parameter usually is -- then by all means, go ahead and throw an exception. That's what they're there for.