# Class HomeException

java.lang.Object
java.lang.Throwable
java.lang.Exception
com.codename1.home.HomeException

Direct Known Subclasses:
  `HomeConfigurationException`

public class HomeException extends Exception

The failure delivered through an `AsyncResource` when a smart-home operation does not succeed. Branch on `getError()` rather than on the message.

    SmartHome.getInstance().write(write).onResult((res, err) -> {
        if (err instanceof HomeException) {
            HomeError e = ((HomeException) err).getError();
            if (e == HomeError.PIN_REQUIRED) {
                promptForLockPin();
            }
        }
    });

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `HomeException(HomeError error, String message)`
  Creates an exception carrying a typed reason.
  `HomeException(HomeError error, String message, String accessoryId)`
  Creates an exception carrying a typed reason and the accessory it applies to.
  `HomeException(HomeError error, String message, String accessoryId, Throwable cause)`
  Creates an exception carrying a typed reason, the accessory it applies to and an underlying cause.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `String`
  `getAccessoryId()`
  The accessory this failure is about, when it is about one.
  `HomeError`
  `getError()`
  The typed reason this operation failed.

  ### Methods inherited from class Throwable

  `addSuppressed, getCause, getLocalizedMessage, getMessage, getStackTrace, getSuppressed, initCause, printStackTrace, printStackTrace, setStackTrace, toString`

  ### Methods inherited from class Object

  `clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- ## Constructor Details

  - ### HomeException

    public HomeException(HomeError error, String message)

    Creates an exception carrying a typed reason.

    ###### Parameters

    - `error`: the typed reason; `null` becomes `HomeError.UNKNOWN`

    - `message`: the platform's own text, or an explanation of a request this API rejected before it reached the platform

  - ### HomeException

    public HomeException(HomeError error, String message, String accessoryId)

    Creates an exception carrying a typed reason and the accessory it applies to.

    ###### Parameters

    - `error`: the typed reason; `null` becomes `HomeError.UNKNOWN`

    - `message`: the platform's own text

    - `accessoryId`: the accessory the failure is about, or `null` when it is not about one in particular

  - ### HomeException

    public HomeException(HomeError error, String message, String accessoryId, Throwable cause)

    Creates an exception carrying a typed reason, the accessory it applies to and an underlying cause.

    ###### Parameters

    - `error`: the typed reason; `null` becomes `HomeError.UNKNOWN`

    - `message`: the platform's own text

    - `accessoryId`: the accessory the failure is about, or `null`

    - `cause`: the underlying failure, or `null`

- ## Method Details

  - ### getError

    public HomeError getError()

    The typed reason this operation failed.

    ###### Returns

    the reason, never `null`

  - ### getAccessoryId

    public String getAccessoryId()

    The accessory this failure is about, when it is about one.

    A batch read or write that fails as a whole has no single accessory and answers `null` here; per-item outcomes inside a batch that partially succeeded are reported through `TraitWriteResult` and `TraitReading` instead, not as exceptions.

    ###### Returns

    the accessory id, or `null`