public class ExceptionUtils extends Object
限定符和类型 | 类和说明 |
---|---|
static interface |
ExceptionUtils.LineChecker |
static interface |
ExceptionUtils.SecureRun<T>
Run in try-catch Throwable, change Throwable to NestedCheckedException
{捕获所有异常和错误}
|
构造器和说明 |
---|
ExceptionUtils() |
限定符和类型 | 方法和说明 |
---|---|
static NestedRuntimeException |
causeException(Throwable e)
Handle
InvocationTargetException, ExceptionInInitializerError,
RuntimeErrorException, SAXException, MBeanException ,
get its nested cause exception in the wrap of NestedRuntimeException. |
static <T> T |
doInSecure(ExceptionUtils.SecureRun<T> runHook)
Run in try-catch Throwable, change Throwable to NestedCheckedException
{捕获所有异常和错误}
|
static String |
errorMsgCut(String errorMsg,
int maxLen)
裁剪错误信息,最多只取 maxLen 个字符(maxLen>=200),规则如下:
【只保留前面8/11的字符+后面3/11的字符】 例如一个数据库的errorMessage长度可达1000个字符,用此方法裁剪后, 假设maxLen=550,那就只保留前400个字符+后150个字符。 |
static String |
getExceptionProfile(Throwable e)
获取精简过的错误信息,(错误类型+错误描述),默认截取440个字符(前320个+后120个)
|
static String |
getExceptionProfile(Throwable e,
int errorLen)
获取精简过的错误信息,(错误类型+错误描述),默认截取440个字符(前320个+后120个)
|
static String |
getExceptionProfile(Throwable e,
String prompt)
获取精简过的错误信息,(错误类型+错误描述),默认截取440个字符(前320个+后120个)
|
static String |
getExceptionProfile(Throwable e,
String prompt,
int errorLen)
获取精简过的错误信息,(错误类型+错误描述),截取 errorLen 个字符。
|
static String |
getStackTraceStr(ExceptionUtils.LineChecker linechecker,
Throwable e)
智能将StackTrace堆栈信息转换成字符串
|
static String |
getStackTraceStr(ExceptionUtils.LineChecker linechecker,
Throwable e,
String prompt)
智能将StackTrace堆栈信息转换成字符串
|
static <T extends Throwable> |
removeFirstStack(T e)
改造堆栈信息,remove第一个堆栈,便于外部调用程序直接定位到自己的调用出处。
|
public static String getStackTraceStr(ExceptionUtils.LineChecker linechecker, Throwable e)
linechecker
- 堆栈过滤器,可为 nulle
- 异常实例public static String getStackTraceStr(ExceptionUtils.LineChecker linechecker, Throwable e, String prompt)
linechecker
- 堆栈过滤器,可为 nulle
- 异常实例prompt
- 附加提示,可为 nullpublic static String getExceptionProfile(Throwable e)
prompt
- 附加提示,可为 nullpublic static String getExceptionProfile(Throwable e, String prompt)
prompt
- 附加提示,可为 nullpublic static String getExceptionProfile(Throwable e, int errorLen)
errorLen
- 截取错误字符串的最大长度,比如 500public static String getExceptionProfile(Throwable e, String prompt, int errorLen)
prompt
- 附加提示,可为 nullerrorLen
- 截取错误字符串的最大长度,比如 500public static String errorMsgCut(String errorMsg, int maxLen)
maxLen
- 截取错误字符串的最大长度,比如500public static <T extends Throwable> T removeFirstStack(T e)
java.lang.IllegalArgumentException: [Assertion failed] - this argument is required; it must not be null at org.zollty.util.AssertTest.doService(AssertTest.java:25)改造前堆栈信息为:
java.lang.IllegalArgumentException: [Assertion failed] - this argument is required; it must not be null at org.zollty.util.AssertTest.notNull(AssertTest.java:123) at org.zollty.util.AssertTest.notNull(AssertTest.java:110) at org.zollty.util.AssertTest.hasText(AssertTest.java:91) at org.zollty.util.AssertTest.hasLength(AssertTest.java:51) at org.zollty.util.AssertTest.doService(AssertTest.java:25)
public static <T> T doInSecure(ExceptionUtils.SecureRun<T> runHook) throws NestedCheckedException
public static NestedRuntimeException causeException(Throwable e)
InvocationTargetException, ExceptionInInitializerError,
RuntimeErrorException, SAXException, MBeanException
,
get its nested cause exception in the wrap of NestedRuntimeException.e
- the nested exception (Probably InvocationTargetException, ExceptionInInitializerError...) to handleCopyright © 2018 jretty-org. All rights reserved.