![JAR search and dependency download from the Maven repository](/logo.png)
mtons.utils.Exceptions Maven / Gradle / Ivy
/*
+--------------------------------------------------------------------------
| mtons [#RELEASE_VERSION#]
| ========================================
| Copyright (c) 2014, 2015 mtons. All Rights Reserved
| http://www.mtons.com
|
+---------------------------------------------------------------------------
*/
package mtons.utils;
import java.io.PrintWriter;
import java.io.StringWriter;
/**
* 关于异常的工具类.
*
*/
public class Exceptions {
/**
* 将ErrorStack转化为String.
* @param e 异常对象
* @return string
*/
public static String buildMessage(Exception e) {
StringWriter stringWriter = new StringWriter();
e.printStackTrace(new PrintWriter(stringWriter));
return stringWriter.toString();
}
/**
* Build a message for the given base message and root cause.
* @param message the base message
* @param cause the root cause
* @return the full exception message
*/
public static String buildMessage(String message, Throwable cause) {
if (cause != null) {
StringBuilder sb = new StringBuilder();
if (message != null) {
sb.append(message).append("; ");
}
sb.append("nested exception is ").append(cause);
return sb.toString();
}
else {
return message;
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy