Cách bỏ qua ngoại lệ

Hỗ trợ Bỏ qua Ngoại lệ

ExceptionManager lớp cung cấp khả năng bỏ qua ngoại lệ:

Ví dụ mã:

Đặt callback để xử lý ngoại lệ:

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");
    }
});

Hoặc sử dụng một phương án thay thế:

//Ignore all exceptions
ExceptionManager.setIgnoreAll(true);

Ngoài ra, bạn có thể đặt callback cho nhật ký ngoại lệ bị bỏ qua:

ExceptionManager.setIgnoreExceptionsLogHandler(new IgnoreExceptionsLogCallback() {
    public void invoke(String message) {
        System.out.println("=== EXCEPTION IGNORED === " + message);
    }
});

Người dùng sẽ được thông báo rằng ngoại lệ có thể được bỏ qua bằng một thông báo lỗi. Ví dụ:

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.