# HG changeset patch # User František Kučera # Date 1387148338 -3600 # Node ID 2ec52027b97fb6aec9fa574ad9de55afc04a59c6 # Parent 4507cb9a0cf14d79f205b451151a7b256344e5d4 better exceptions diff -r 4507cb9a0cf1 -r 2ec52027b97f java/sql-dk/src/info/globalcode/sql/dk/CLIParser.java --- a/java/sql-dk/src/info/globalcode/sql/dk/CLIParser.java Sun Dec 15 23:54:51 2013 +0100 +++ b/java/sql-dk/src/info/globalcode/sql/dk/CLIParser.java Sun Dec 15 23:58:58 2013 +0100 @@ -27,7 +27,7 @@ types = Collections.unmodifiableMap(m); } - public CLIOptions parseOptions(String[] args) { + public CLIOptions parseOptions(String[] args) throws CLIParserException { CLIOptions options = new CLIOptions(); List numberedTypes = new ArrayList<>(); @@ -86,9 +86,9 @@ try { paramType = numberedTypes.get(paramIndex); } catch (IndexOutOfBoundsException e) { - throw new IllegalArgumentException("Missing type for parameter #" + paramIndex, e); + throw new CLIParserException("Missing type for parameter #" + paramIndex, e); } catch (NullPointerException e) { - throw new IllegalArgumentException("Invalid type definition for parameter #" + paramIndex, e); + throw new CLIParserException("Invalid type definition for parameter #" + paramIndex, e); } parameter = new Parameter(arg, paramType); } @@ -97,17 +97,17 @@ } break; default: - throw new IllegalArgumentException("Unknown option: " + arg); + throw new CLIParserException("Unknown option: " + arg); } } return options; } - private String fetchNext(String[] args, int index) { + private String fetchNext(String[] args, int index) throws CLIParserException { if (index < args.length) { return args[index]; } else { - throw new IllegalArgumentException("Expecting value for option: " + args[index - 1]); + throw new CLIParserException("Expecting value for option: " + args[index - 1]); } } @@ -126,10 +126,10 @@ } } - private int getType(String typeString) { + private int getType(String typeString) throws CLIParserException { Integer type = types.get(typeString); if (type == null) { - throw new IllegalArgumentException("Unsupported type: " + typeString); + throw new CLIParserException("Unsupported type: " + typeString); } else { return type; } diff -r 4507cb9a0cf1 -r 2ec52027b97f java/sql-dk/src/info/globalcode/sql/dk/CLIParserException.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/java/sql-dk/src/info/globalcode/sql/dk/CLIParserException.java Sun Dec 15 23:58:58 2013 +0100 @@ -0,0 +1,23 @@ +package info.globalcode.sql.dk; + +/** + * + * @author Ing. František Kučera (frantovo.cz) + */ +public class CLIParserException extends Exception { + + public CLIParserException() { + } + + public CLIParserException(String message) { + super(message); + } + + public CLIParserException(Throwable cause) { + super(cause); + } + + public CLIParserException(String message, Throwable cause) { + super(message, cause); + } +} diff -r 4507cb9a0cf1 -r 2ec52027b97f java/sql-dk/test/info/globalcode/sql/dk/CLIParserTest.java --- a/java/sql-dk/test/info/globalcode/sql/dk/CLIParserTest.java Sun Dec 15 23:54:51 2013 +0100 +++ b/java/sql-dk/test/info/globalcode/sql/dk/CLIParserTest.java Sun Dec 15 23:58:58 2013 +0100 @@ -24,7 +24,7 @@ } @Test - public void testParseOptions_QueryNow_Numbered() throws InvalidOptionsException { + public void testParseOptions_QueryNow_Numbered() throws InvalidOptionsException, CLIParserException { String[] args = new String[]{Tokens.DB, DATABASE_NAME_1, Tokens.SQL, SQL_1, Tokens.DATA, DATA_1, DATA_2, DATA_3}; CLIOptions options = parser.parseOptions(args); options.validate(); @@ -42,8 +42,8 @@ } @Test - public void testParseOptions_QueryNow_Named() throws InvalidOptionsException { - String[] args = new String[]{Tokens.DB, DATABASE_NAME_1, Tokens.SQL, SQL_1, Tokens.TYPES}; + public void testParseOptions_QueryNow_Named() throws InvalidOptionsException, CLIParserException { + String[] args = new String[]{Tokens.DB, DATABASE_NAME_1, Tokens.SQL, SQL_1}; CLIOptions options = parser.parseOptions(args); options.validate(); @@ -53,7 +53,7 @@ } @Test - public void testParseOptions_PrepareBatch() throws InvalidOptionsException { + public void testParseOptions_PrepareBatch() throws InvalidOptionsException, CLIParserException { String[] args = new String[]{Tokens.BATCH, Tokens.SQL, SQL_1}; CLIOptions options = parser.parseOptions(args); options.validate(); @@ -63,7 +63,7 @@ } @Test - public void testParseOptions_ExecuteBatch() throws InvalidOptionsException { + public void testParseOptions_ExecuteBatch() throws InvalidOptionsException, CLIParserException { String[] args = new String[]{Tokens.BATCH, Tokens.DB, DATABASE_NAME_1}; CLIOptions options = parser.parseOptions(args); options.validate();