1 changed files with 27 additions and 0 deletions
@ -0,0 +1,27 @@ |
|||
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; |
|||
} |
|||
} |
|||
Loading…
Reference in new issue