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

io.mosip.kernel.masterdata.utils.ExceptionUtils Maven / Gradle / Ivy

There is a newer version: 1.2.1.0
Show newest version
package io.mosip.kernel.masterdata.utils;

import java.util.Optional;
import java.util.stream.Stream;

/**
 * This class is used to get the Exception related functionalities.
 * 
 * @author Urvil Joshi
 * @author Bal Vikash Sharma
 * @author Sagar Mahapatra
 * @author Ritesh Sinha
 * @author Dharmesh Khandelwal
 * 
 * @since 1.0.0
 */
public final class ExceptionUtils {
	/**
	 * Constructor for ExceptionUtils class.
	 */
	private ExceptionUtils() {
		super();
	}

	/**
	 * Method to find the root cause of the exception.
	 * 
	 * @param exception the exception.
	 * @return the root cause.
	 */
	public static String parseException(Throwable exception) {
		Optional rootCause = Stream.iterate(exception, Throwable::getCause)
				.filter(element -> element.getCause() == null).findFirst();
		String cause = rootCause.isPresent() ? rootCause.get().getMessage() : exception.getMessage();
		return " " + cause;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy