如何忽略异常
Contents
[
Hide
]
忽略异常支持
ExceptionManager 类提供忽略异常的能力:
代码示例:
设置回调以处理异常:
ExceptionManager.setIgnoreExceptionsHandler(new IgnoreExceptionsCallback() {
//exception path: {Module}\{Method}\{Action}\{GUID}
//example: MailMessage\Load\DecodeTnefAttachment\64149867-679e-4645-9af0-d46566cae598
public boolean invoke(AsposeException ex, String path) {
//Ignore all exceptions on MailMessage.Load
return path.equals("MailMessage\\Load");
}
});
或使用替代方案:
//Ignore all exceptions
ExceptionManager.setIgnoreAll(true);
此外,您可以为被忽略的异常日志设置回调函数:
ExceptionManager.setIgnoreExceptionsLogHandler(new IgnoreExceptionsLogCallback() {
public void invoke(String message) {
System.out.println("=== EXCEPTION IGNORED === " + message);
}
});
系统会通过错误消息通知用户该异常可以被忽略。例如:
Exceptioin message:
AsposeArgumentException: properties should not be empty.
If you want to ignore an exception and want to proceed further then you can use:
ExceptionManager.getIgnoreList().add("MailMessage\\Load\\DecodeTnefAttachment\\64149867-679e-4645-9af0-d46566cae598")
Invalid TNEF Attachment will be interpreted as regular attachment.