make ConfigException abstract

This commit is contained in:
Havoc Pennington 2011-11-30 09:24:46 -05:00
parent 9f9b351f0e
commit 9689abd781
2 changed files with 23 additions and 5 deletions

View File

@ -7,7 +7,7 @@ package com.typesafe.config;
/**
* All exceptions thrown by the library are subclasses of ConfigException.
*/
public class ConfigException extends RuntimeException {
public abstract class ConfigException extends RuntimeException {
private static final long serialVersionUID = 1L;
final private ConfigOrigin origin;
@ -343,4 +343,20 @@ public class ConfigException extends RuntimeException {
return sb.toString();
}
}
/**
* Exception that doesn't fall into any other category.
*/
public static class Generic extends ConfigException {
private static final long serialVersionUID = 1L;
public Generic(String message, Throwable cause) {
super(message, cause);
}
public Generic(String message) {
this(message, null);
}
}
}

View File

@ -123,8 +123,9 @@ public final class ConfigFactory {
if (specified == 0) {
return load("application");
} else if (specified > 1) {
throw new ConfigException(
"You set more than one system property from config.file, config.url, config.resource; don't know which one to use!");
throw new ConfigException.Generic("You set more than one of config.file='" + file
+ "', config.url='" + url + "', config.resource='" + resource
+ "'; don't know which one to use!");
} else {
if (resource != null) {
// this deliberately does not parseResourcesAnySyntax; if
@ -136,8 +137,9 @@ public final class ConfigFactory {
try {
return load(parseURL(new URL(url)));
} catch (MalformedURLException e) {
throw new ConfigException("Bad URL in config.url system property: '" + url
+ "'", e);
throw new ConfigException.Generic(
"Bad URL in config.url system property: '" + url + "': "
+ e.getMessage(), e);
}
}
}