package cn.superdesk.uniorder.common.exception.utils;

//import javax.validation.ConstraintViolationException;
import java.io.PrintWriter;
import java.io.StringWriter;


/**
 * @Description: 异常工具
 * @Author: linjinyu
 * @CreateDate: 2020/12/23 下午2:22
 * @UpdateUser: linjinyu
 * @UpdateDate: 2020/12/23 下午2:22
 * @UpdateRemark: 修改内容
 * @Version: 1.0
 */
public class ExceptionThrowableUtils {

	/**
	 * 获取堆栈信息
	 *
	 * @param throwable
	 * @return
	 */
	public static String getStackTrace(Throwable throwable) {
		StringWriter sw = new StringWriter();
		try (PrintWriter pw = new PrintWriter(sw)) {
			throwable.printStackTrace(pw);
			return sw.toString();
		}
	}

//	/**
//	 * @param e
//	 * @param msg
//	 */
//	public static void throwForeignKeyException(Throwable e, String msg) {
//		Throwable t = e.getCause();
//		while ((t != null) && !(t instanceof ConstraintViolationException)) {
//			t = t.getCause();
//		}
//		if (t != null) {
//			throw new BadRequestException(msg);
//		}
//		assert false;
//		throw new BadRequestException("删除失败:" + t.getMessage());
//	}
}
