Coding Exceptions in Agent Operations

When an operation method throws an exception, you can either use the implicit status code associated with the exception class, or encode the HTTP status code explicitly.

Procedure

  1. Create and throw an exception object.
    final String errorMessage = MessageFormat.format(
        "Cannot start web application ''{0}'' because it is already running.",
           tomcatWebAppConfig.getName());
    throw new TeaIllegalStateException(errorMessage);
  2. Optional. Supply an explicit status code (which overwrites the implicit status code).
    You must not supply 303 as an explicit status code. Status 303 has special meaning for the server.
    throw new TeaIllegalStateException("Too many requests").withHttpStatusCode(429);
  3. Optional. Supply an explicit exit code for the shell interface.
    In the shell interface an operation returns an exit code when it returns in error. When constructing the exception in your operation method, you may supply a positive integer as the shell exit code.

    If you do not supply an explicit exit code, the shell command returns an implicit exit code that is appropriate to the return status of the operation.