EntityAlreadyExistsException.java

  1. package edu.ucsb.cs156.rec.errors;

  2. /**
  3.  * This is an error class for a custom RuntimeException in Java that is used to indicate
  4.  * when an entity of a specific type with a given ID already exists in the repository.
  5.  */
  6. public class EntityAlreadyExistsException extends RuntimeException {
  7.   /**
  8.    * Constructor for the exception
  9.    *
  10.    * @param entityType The class of the entity that already existed, e.g. User.class
  11.    * @param type the type that was trying to be saved
  12.    */
  13.   public EntityAlreadyExistsException(Class<?> entityType, Object type) {
  14.     super("%s %s already exists"
  15.       .formatted(entityType.getSimpleName(), type.toString()));
  16.   }
  17. }