You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
27 lines
1.0 KiB
27 lines
1.0 KiB
package com.crawler.exception.handler;
|
|
|
|
import com.crawler.exception.DataExtractException;
|
|
import com.crawler.exception.HtmlParseException;
|
|
import com.crawler.exception.ParseException;
|
|
import com.crawler.exception.ExceptionHandler;
|
|
import com.crawler.view.CrawlerView;
|
|
|
|
public class ParseExceptionHandler implements ExceptionHandler {
|
|
@Override
|
|
public void handle(Exception e, CrawlerView view) {
|
|
if (e instanceof HtmlParseException) {
|
|
HtmlParseException ex = (HtmlParseException) e;
|
|
view.showErrorMessage("HTML解析失败,URL: " + ex.getSourceUrl());
|
|
} else if (e instanceof DataExtractException) {
|
|
DataExtractException ex = (DataExtractException) e;
|
|
view.showErrorMessage("数据提取失败,字段: " + ex.getExtractField());
|
|
} else {
|
|
view.showErrorMessage("解析异常: " + e.getMessage());
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public Class<? extends Exception> getSupportedExceptionType() {
|
|
return ParseException.class;
|
|
}
|
|
}
|