Using DiscoveryException and AutomationException

When writing Discovery sensors and sensor-related scripts, you may want to use DiscoveryException or AutomationException to indicate that an exception has come from Discovery.

The DiscoveryException script include extends AutomationException, which extends the GenericException class. The following example uses DiscoveryException to throw an exception:
function foo() { 
  if(//condition matches) throw new DiscoveryException("The message", "The cause"); }
The first argument takes the message of the exception and the second argument (optional) takes the cause of the exception. You may also want to catch the exception and log it as shown in the example below:
try {
catch(e) { 
  if(e instanceof DiscoveryException)
    gs.log("A DiscoveryException occurred. It is " + e.getMessage() + " caused by " + e.getCause()); }

The above example also applies for AutomationException. DiscoveryException is typically used to provide exception processing specifically for Discovery, while AutomationException is used for exception processing that applies to both Orchestration and Discovery.