Java - click(Rectangle) ought to throw exception

Asked by John Henckel

Probably i'm stupid, but twice now I've tried to call

region.click(rect)

where rect is java.awt.Rectangle, which is not a supported target type.

The function simply does nothing and returns 0 (which i ignore).

Don't you suppose it would be better if it throws FindFailed? or else UnsupportedTargetType?

  private <PSIMRL> Location getLocationFromTarget(PSIMRL target) throws FindFailed {
    if (target instanceof Pattern || target instanceof String || target instanceof Image) {
      Match m = find(target);
      if (m != null) {
        if (isOtherScreen()) {
          return m.getTarget().setOtherScreen(scr);
        } else {
          return m.getTarget();
        }
      }
      return null; <======== SHOULD BE A THROW FINDFAILED
    }
    if (target instanceof Match) {
      return ((Match) target).getTarget();
    }
    if (target instanceof Region) {
      return ((Region) target).getCenter();
    }
    if (target instanceof Location) {
      return new Location((Location) target);
    }
    return null; <======== SHOULD BE A THROW BAD TARGET TYPE
  }

I can't see any situation where return null is helpful. I think a throw is better.

Question information

Language:
English Edit question
Status:
Solved
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Solved by:
RaiMan
Solved:
Last query:
Last reply:
Revision history for this message
John Henckel (henckel-jonathan) said :
#1

p.s. the correct invocation is region.click(new Region(rect)). But the point is, click(rect) should throw something.

Revision history for this message
Best RaiMan (raimund-hocke) said :
#2

good point.

... but
- the Sikuli functions should support Java Rectangle and Point (I will add it in version 1.2)
- a not supported parameter should throw an exception, but it should not be FindFailed but an adequate standard Java "not supported ...." exception.

Revision history for this message
John Henckel (henckel-jonathan) said :
#3

sounds perfect

Revision history for this message
John Henckel (henckel-jonathan) said :
#4

Thanks RaiMan, that solved my question.