From 9689abd78123899aa8cdb619dd032120482aef05 Mon Sep 17 00:00:00 2001 From: Havoc Pennington Date: Wed, 30 Nov 2011 09:24:46 -0500 Subject: [PATCH] make ConfigException abstract --- .../com/typesafe/config/ConfigException.java | 18 +++++++++++++++++- .../com/typesafe/config/ConfigFactory.java | 10 ++++++---- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/config/src/main/java/com/typesafe/config/ConfigException.java b/config/src/main/java/com/typesafe/config/ConfigException.java index ecf5d85e..8c23d095 100644 --- a/config/src/main/java/com/typesafe/config/ConfigException.java +++ b/config/src/main/java/com/typesafe/config/ConfigException.java @@ -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); + } + } + } diff --git a/config/src/main/java/com/typesafe/config/ConfigFactory.java b/config/src/main/java/com/typesafe/config/ConfigFactory.java index 31acf3de..9251b3fb 100644 --- a/config/src/main/java/com/typesafe/config/ConfigFactory.java +++ b/config/src/main/java/com/typesafe/config/ConfigFactory.java @@ -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); } } }