diff --git a/src/net/sourceforge/schemaspy/Main.java b/src/net/sourceforge/schemaspy/Main.java index 2837bce..96a4eae 100755 --- a/src/net/sourceforge/schemaspy/Main.java +++ b/src/net/sourceforge/schemaspy/Main.java @@ -14,6 +14,14 @@ public static void main(String[] argv) throws Exception { SchemaAnalyzer analyzer = new SchemaAnalyzer(); - System.exit(analyzer.analyze(new Config(argv))); + int rc = 1; + + try { + rc = analyzer.analyze(new Config(argv)); + } catch (Exception exc) { + System.err.println(exc); + } + + System.exit(rc); } } \ No newline at end of file diff --git a/src/net/sourceforge/schemaspy/model/InvalidConfigurationException.java b/src/net/sourceforge/schemaspy/model/InvalidConfigurationException.java new file mode 100644 index 0000000..2179e2f --- /dev/null +++ b/src/net/sourceforge/schemaspy/model/InvalidConfigurationException.java @@ -0,0 +1,24 @@ +package net.sourceforge.schemaspy.model; + +/** + * @author John Currier + */ +public class InvalidConfigurationException extends RuntimeException { + private static final long serialVersionUID = 1L; + + public InvalidConfigurationException() { + super(); + } + + public InvalidConfigurationException(String msg) { + super(msg); + } + + public InvalidConfigurationException(Throwable cause) { + super(cause); + } + + public InvalidConfigurationException(String msg, Throwable cause) { + super(msg, cause); + } +} diff --git a/src/net/sourceforge/schemaspy/model/xml/SchemaMeta.java b/src/net/sourceforge/schemaspy/model/xml/SchemaMeta.java index 88cc678..eaeec79 100644 --- a/src/net/sourceforge/schemaspy/model/xml/SchemaMeta.java +++ b/src/net/sourceforge/schemaspy/model/xml/SchemaMeta.java @@ -15,6 +15,7 @@ import javax.xml.validation.SchemaFactory; import javax.xml.validation.Validator; import net.sourceforge.schemaspy.Config; +import net.sourceforge.schemaspy.model.InvalidConfigurationException; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.Node; @@ -29,8 +30,7 @@ public class SchemaMeta { private final String comments; private final File metaFile; - @SuppressWarnings("null") // System.exit() results in compiler complaints about null doc refs - public SchemaMeta(String xmlMeta, String dbName, String schema) { + public SchemaMeta(String xmlMeta, String dbName, String schema) throws InvalidConfigurationException { File meta = new File(xmlMeta); if (meta.isDirectory()) { String filename = (schema == null ? dbName : schema) + ".meta.xml"; @@ -45,19 +45,17 @@ public SchemaMeta(String xmlMeta, String dbName, String schema) { return; } - System.err.println("Meta directory \"" + xmlMeta + "\" must contain a file named \"" + filename + '\"'); - System.exit(2); + throw new InvalidConfigurationException("Meta directory \"" + xmlMeta + "\" must contain a file named \"" + filename + '\"'); } } else if (!meta.exists()) { - System.err.println("Specified meta file \"" + xmlMeta + "\" does not exist"); - System.exit(2); + throw new InvalidConfigurationException("Specified meta file \"" + xmlMeta + "\" does not exist"); } metaFile = meta; Document doc = parse(metaFile); if (doc == null) { - System.exit(1); + throw new InvalidConfigurationException(); } NodeList commentsNodes = doc.getElementsByTagName("comments");