# Class HealthException

java.lang.Object
java.lang.Throwable
java.lang.Exception
com.codename1.health.HealthException

public class HealthException extends Exception

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

    store.write(sample).onResult((res, err) -> {
        if (err instanceof HealthException) {
            HealthError e = ((HealthException) err).getError();
            if (e == HealthError.UNAUTHORIZED) {
                Health.getInstance().openHealthSettings();
            }
        }
    });

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `HealthException(HealthError error, String message)`
  Creates an exception carrying a typed reason.
  `HealthException(HealthError error, String message, Throwable cause)`
  Creates an exception carrying a typed reason and an underlying cause.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `HealthError`
  `getError()`
  `HealthWriteResult`
  `getPartialResult()`
  Samples already committed before the failure, when a chunked write fails partway.

  ### Methods inherited from class Throwable

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

  ### Methods inherited from class Object

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

- ## Constructor Details

  - ### HealthException

    public HealthException(HealthError error, String message)
    Creates an exception carrying a typed reason.

  - ### HealthException

    public HealthException(HealthError error, String message, Throwable cause)
    Creates an exception carrying a typed reason and an underlying cause.

- ## Method Details

  - ### getPartialResult

    public HealthWriteResult getPartialResult()

    Samples already committed before the failure, when a chunked write fails partway.

    A write larger than `HealthStore.getMaxWriteBatchSize()` is sent in chunks, and an earlier chunk can be stored before a later one fails. Without this the caller sees only the failure, retries the whole batch, and writes the committed samples a second time -- duplicate records in the user's health store. Null when the failure was not a partial write.

  - ### getError

    public HealthError getError()