Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Granularity in exception #428

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.apache.http.message.BasicHeader;

import edu.uci.ics.crawler4j.crawler.authentication.AuthInfo;
import edu.uci.ics.crawler4j.crawler.exceptions.ConfigException;

public class CrawlConfig {

Expand Down Expand Up @@ -238,22 +239,22 @@ public DnsResolver getDnsResolver() {
/**
* Validates the configs specified by this instance.
*
* @throws Exception on Validation fail
* @throws ConfigException on Validation fail
*/
public void validate() throws Exception {
public void validate() throws ConfigException {
if (crawlStorageFolder == null) {
throw new Exception("Crawl storage folder is not set in the CrawlConfig.");
throw new ConfigException("Crawl storage folder is not set in the CrawlConfig.");
}
if (politenessDelay < 0) {
throw new Exception("Invalid value for politeness delay: " + politenessDelay);
throw new ConfigException("Invalid value for politeness delay: " + politenessDelay);
}
if (maxDepthOfCrawling < -1) {
throw new Exception(
throw new ConfigException(
"Maximum crawl depth should be either a positive number or -1 for unlimited depth" +
".");
}
if (maxDepthOfCrawling > Short.MAX_VALUE) {
throw new Exception("Maximum value for crawl depth is " + Short.MAX_VALUE);
throw new ConfigException("Maximum value for crawl depth is " + Short.MAX_VALUE);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public CrawlController(CrawlConfig config, PageFetcher pageFetcher, Parser parse
if (folder.mkdirs()) {
logger.debug("Created folder: " + folder.getAbsolutePath());
} else {
throw new Exception(
throw new IOException(
"couldn't create the storage folder: " + folder.getAbsolutePath() +
" does it already exist ?");
}
Expand All @@ -128,7 +128,7 @@ public CrawlController(CrawlConfig config, PageFetcher pageFetcher, Parser parse
if (envHome.mkdir()) {
logger.debug("Created folder: " + envHome.getAbsolutePath());
} else {
throw new Exception(
throw new IOException(
"Failed creating the frontier folder: " + envHome.getAbsolutePath());
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package edu.uci.ics.crawler4j.crawler.exceptions;

/**
* Created by Dario Goikoetxea on 24/1/2020.
*
* Thrown when there is a problem with the configuration
*/
public class ConfigException extends Exception {
private static final long serialVersionUID = -7376208295930945704L;

public ConfigException() {
super();
}

public ConfigException(Throwable cause) {
super(cause);
}

public ConfigException(String message, Throwable cause) {
super(message, cause);
}

public ConfigException(String message) {
super(message);
}

}