All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.dakusui.processstreamer.exceptions.Exceptions Maven / Gradle / Ivy

There is a newer version: 1.0.4
Show newest version
package com.github.dakusui.processstreamer.exceptions;

import java.util.function.Function;

public enum Exceptions {
  ;

  public static  T wrap(Throwable throwable) {
    throw wrap(throwable, InternalException::new);
  }

  public static  T wrap(Throwable throwable, Function exceptionFactory) {
    if (throwable instanceof Error)
      throw (Error) throwable;
    if (throwable instanceof RuntimeException)
      throw (RuntimeException) throwable;
    throw exceptionFactory.apply(throwable);
  }

  public static IllegalStateException illegalState(Object currentState, String requirement) {
    throw new IllegalStateException(String.format("Current state=<%s>, while it should be <%s>", currentState, requirement));
  }

  public static InternalException illegalException(Throwable t) {
    throw new InternalException("This exception shouldn't be thrown here", t);
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy