When a plugin throws an exception, the related end user messaging can be handled automatically, for example setting the plugin description accordingly and stopping the plugin itself.
Here is an example of correct exception handling in onRun()
@Override
public void onStart() throws PluginStartupException {
try {
// This code may generate a SerialPortException if there are connection problems
serial = new SerialHelper(PORTNAME, BAUDRATE, DATABITS, STOPBITS, PARITY, new SerialPortListener() {
@Override
public void onDataAvailable(String data) {
LOG.info("MySensors received: " + data);
sendChanges(data);
}
});
serial.setChunkTerminator("\n");
} catch (SerialPortException ex) {
throw new PluginStartupException("Error while connecting to serial device", ex);
}
}
After catching the exception Freedomotic will: