DomainException.java

  1. package de.japrost.jabudget.domain;

  2. /**
  3.  * Thrown on exceptions handling the domain.
  4.  */
  5. // TODO generate messages
  6. public class DomainException extends Exception {

  7.     private static final long serialVersionUID = 1L;
  8.     private final DomainFailure failure;

  9.     /**
  10.      * Create an instance based on a {@link Throwable}.
  11.      *
  12.      * @param failure the failure code
  13.      * @param cause the cause of the failure
  14.      */
  15.     public DomainException(DomainFailure failure, Throwable cause) {
  16.         super(failure.toString(), cause);
  17.         this.failure = failure;
  18.     }

  19.     /**
  20.      * Create an instance.
  21.      *
  22.      * @param failure the failure code
  23.      */
  24.     public DomainException(DomainFailure failure) {
  25.         super(failure.toString());
  26.         this.failure = failure;
  27.     }

  28.     /**
  29.      * Get the failure code.
  30.      *
  31.      * @return the code
  32.      */
  33.     public DomainFailure getFailure() {
  34.         return failure;
  35.     }

  36. }