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

panda.dao.DaoException Maven / Gradle / Ivy

Go to download

Panda Core is the core module of Panda Framework, it contains commonly used utility classes similar to apache-commons.

There is a newer version: 1.8.0
Show newest version
package panda.dao;

/**
 * 
 *
 */
public class DaoException extends RuntimeException {

	private static final long serialVersionUID = 1L;

	public DaoException() {
		super();
	}

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

	public DaoException(Throwable cause) {
		super(cause);
	}

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

	public static  DaoException create(T obj, String fieldName, String name) {
		return new DaoException(String.format("Fail to %s [%s]->[%s]", name,
			obj == null ? "NULL object" : obj.getClass().getName(), fieldName));
	}
	
	public static  DaoException create(T obj, String fieldName, String name, Exception e) {
		if (e == null) {
			return create(obj, fieldName, name);
		}

		if (e instanceof DaoException) {
			return (DaoException)e;
		}

		return new DaoException(String.format("Fail to %s [%s]->[%s], because: '%s'", name,
			obj == null ? "NULL object" : obj.getClass().getName(), fieldName, e.getMessage()), e);
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy