I want to make tests in a constructor to find out if it is currently a good idea to instantiate the object or not, with the given parameters. But how could I abort and return a warning from a constructor to the new statement? Must such tests instead be done by the caller before each “new” statement? I thought that the constructor would be a good place for it.
Share
You could use a factory object instead. This could then run your checks and return the instansiated object, or null. This would probably be more efficient than an exception.