I come from a Java background, and my colleague is from .NET. We are working on a Java project and I saw him create a method like this:
public Object myMethod(Object[] param1, ErrorMessage errorMessage) {...}
ErrorMessage
is a self-defined object that just holds a String
, and is checked if empty or not in the caller.
I have encountered this years ago, and am quite surprised to see it again now. I am more partial to just throwing a RuntimeException
, but then again isn't the try-catch clause just doing the same thing as if(!errorMessage.isEmpty())
?
Is it an anti-pattern? What is it called? I feel that I am ill-equipped to argue my point, and so the code just sits there, haunting me.