OsynthException.java

  1. package com.github.dakusui.osynth.exceptions;

  2. import java.lang.reflect.InvocationTargetException;

  3. public class OsynthException extends RuntimeException {
  4.   public OsynthException(Throwable e) {
  5.     super(e);
  6.   }

  7.   public OsynthException(String message) {
  8.     super(message);
  9.   }

  10.   public OsynthException(String message, Throwable cause) {
  11.     super(message, cause);
  12.   }

  13.   public static OsynthException from(String customMessage, Throwable e) {
  14.     if (e instanceof Error)
  15.       throw (Error) e;
  16.     if (e instanceof InvocationTargetException)
  17.       // False-missing coverage because of JaCoCo limitation
  18.       throw from(customMessage, ((InvocationTargetException) e).getTargetException());
  19.     else if (e instanceof OsynthException)
  20.       if (e.getCause() == null)
  21.         throw (OsynthException) e;
  22.       else
  23.         // False-missing coverage because of JaCoCo limitation
  24.         throw from(customMessage, e.getCause());
  25.     else if (e instanceof RuntimeException)
  26.       throw (RuntimeException)e;
  27.     else {
  28.       if (customMessage == null)
  29.         throw new OsynthException(e);
  30.       else
  31.         throw new OsynthException(customMessage, e);
  32.     }
  33.   }
  34. }