Sunday, August 19, 2007

an observation and SensorPropertiesException

just a strange observation that i had... out of hackystat-sensor-ant, hackystat-sensor-shell, hackystat-sensorbase-uh, hackystat-utilities i think there is just one Exception class. until i look at the code i guess that doesn't really mean anything, but i wonder how the implementations are handling error conditions. anyway, i'm not saying thats bad (well, i guess i don't know at this point), but it smells funny.

IllegalArgumentException vs a check exception
so, i thought about what i'm doing for Issue 9 in the SensorProperties class. i'm throwing a checked exception when the sensor properties file is invalid (missing, not readable, etc). so, why i don't i throw a unchecked IllegalArgumentException? Hm... I think thats because, this error should be handled by the clients. see this little article (i looked it up to make sure i was right).
  • Client code cannot do anything - Make it an unchecked exception

  • Client code will take some useful recovery action based on information in exception - Make it a checked exception

  • In our case, all the client should do is report to the user that the SensorProperties is invalid and to configure it. In my mind that is a useful recovery action. Moreover, in some ways it forces the clients to check and report problems with the configuration.

    so, to conclude, i think this is my justification for doing the way i'm doing it. any problems with that?

    No comments: