java - What Exception is thrown when an implementation breaks its interface's contract? -
through amount of debugging (i not wish repeat) i've found circumstance can arrived @ if 1 of objects given comparator breaks interface's contract (namely comparator compare(a, a)
returns non-zero value).
what kind of exception should throw?
i thought take inspiration treemap, takes comparator, acts bizarrely (not throwing exception) if give nonsense comparator.
the common way use java.lang.illegalargumentexception
:
throw new illegalargumentexception("one of objects given breaks comparators interface contract ");
you can take @ documentation:
thrown indicate method has been passed illegal or inappropriate argument.
Comments
Post a Comment