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

org.springframework.exception.AbstractException Maven / Gradle / Ivy

The newest version!
package org.springframework.exception;

import org.springframework.core.NestedExceptionUtils;
import org.springframework.core.NestedRuntimeException;

/**
 * @see org.springframework.core.NestedRuntimeException
 */
public abstract class AbstractException extends RuntimeException {
  private static final long serialVersionUID = 2992018053912070461L;

  static {
    NestedExceptionUtils.class.getName();
  }

  public AbstractException(String message) {
    super(message);
  }

  public AbstractException(String message, Throwable cause) {
    super(message, cause);
  }

  @Override
  public String getMessage() {
    return NestedExceptionUtils.buildMessage(super.getMessage(), getCause());
  }

  @Override
  public String getLocalizedMessage() {
    return super.getMessage();
  }

  public Throwable getRootCause() {
    Throwable rootCause = null;
    Throwable cause = getCause();
    while (cause != null && cause != rootCause) {
      rootCause = cause;
      cause = cause.getCause();
    }
    return rootCause;
  }

  public Throwable getMostSpecificCause() {
    Throwable rootCause = getRootCause();
    return (rootCause != null ? rootCause : this);
  }

  public boolean contains(Class exType) {
    if (exType == null) {
      return false;
    }
    if (exType.isInstance(this)) {
      return true;
    }
    Throwable cause = getCause();
    if (cause == this) {
      return false;
    }
    if (cause instanceof NestedRuntimeException) {
      return ((NestedRuntimeException) cause).contains(exType);
    }
    else {
      while (cause != null) {
        if (exType.isInstance(cause)) {
          return true;
        }
        if (cause.getCause() == cause) {
          break;
        }
        cause = cause.getCause();
      }
      return false;
    }
  }

  public abstract String getCode();

  public abstract int getStatus();

  public abstract Object[] getArgs();
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy