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

net.anthavio.httl.HttlException Maven / Gradle / Ivy

The newest version!
package net.anthavio.httl;

import java.io.PrintStream;
import java.io.PrintWriter;
import java.net.ConnectException;
import java.net.SocketTimeoutException;

/**
 * 
 * @author martin.vanek
 *
 */
public class HttlException extends RuntimeException {

	private static final long serialVersionUID = 1L;

	private final Exception delegate;

	protected HttlException(String message) {
		super(message);
		this.delegate = null;
	}

	public HttlException(Exception x) {
		super(x);
		this.delegate = x;
	}

	public Exception getException() {
		return delegate;
	}

	/**
	 * If connect refused | connect timeout | read timeout
	 */
	public boolean isConnectOrReadTimeout() {
		return delegate instanceof ConnectException || delegate instanceof SocketTimeoutException;
	}

	@Override
	public void printStackTrace() {
		if (delegate != null) {
			System.out.println(this);
			delegate.printStackTrace();
		} else {
			super.printStackTrace();
		}
	}

	@Override
	public void printStackTrace(PrintStream s) {
		if (delegate != null) {
			s.println(this);
			delegate.printStackTrace(s);
		} else {
			super.printStackTrace(s);
		}
	}

	@Override
	public void printStackTrace(PrintWriter s) {
		if (delegate != null) {
			s.println(this);
			delegate.printStackTrace(s);
		} else {
			super.printStackTrace(s);
		}
	}

	@Override
	public StackTraceElement[] getStackTrace() {
		if (delegate != null) {
			return delegate.getStackTrace();
		} else {
			return super.getStackTrace();
		}
	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy