Skip to content

Commit

Permalink
Get rid of (almost) all System.exits
Browse files Browse the repository at this point in the history
  • Loading branch information
johncurrier committed Aug 26, 2008
1 parent 15bb319 commit 1674402
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 8 deletions.
10 changes: 9 additions & 1 deletion src/net/sourceforge/schemaspy/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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);
}
}
12 changes: 5 additions & 7 deletions src/net/sourceforge/schemaspy/model/xml/SchemaMeta.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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";
Expand All @@ -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");
Expand Down

0 comments on commit 1674402

Please sign in to comment.