code: public static <E extends BaseException> E createNew(Class<E> exceptionType, ErrorCode errorCode) {
          try {
              Constructor<E> constructor = exceptionType.getDeclaredConstructor(ErrorCode.class);
              constructor.setAccessible(true);
              return constructor.newInstance(errorCode);
          } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException
                  | InstantiationException e) {
              throw new IllegalArgumentException(exceptionType.getCanonicalName()
                      + " must implement a constructor with ErrorCode as parameter", e);
          }
      }
docs: Create a new subclass of BaseException from an {@link ErrorCode}.
  
  @param exceptionType the subclass of BaseException to create.
  @param errorCode     the error code to set.
  @param <E>           the subtype.
  @return the created BaseException.