expect invalid regexp in prefix/suffix and throw wrapped exception → better exit code v_0
authorFrantišek Kučera <franta-hg@frantovo.cz>
Wed, 25 Dec 2013 20:52:41 +0100
branchv_0
changeset 61deba1f6600f8
parent 60 d4e88172a363
child 62 7a88ac6ba40c
expect invalid regexp in prefix/suffix and throw wrapped exception → better exit code
java/sql-dk/src/info/globalcode/sql/dk/SQLCommandNamed.java
     1.1 --- a/java/sql-dk/src/info/globalcode/sql/dk/SQLCommandNamed.java	Wed Dec 25 16:38:05 2013 +0100
     1.2 +++ b/java/sql-dk/src/info/globalcode/sql/dk/SQLCommandNamed.java	Wed Dec 25 20:52:41 2013 +0100
     1.3 @@ -28,6 +28,7 @@
     1.4  import java.util.logging.Logger;
     1.5  import java.util.regex.Matcher;
     1.6  import java.util.regex.Pattern;
     1.7 +import java.util.regex.PatternSyntaxException;
     1.8  
     1.9  /**
    1.10   *
    1.11 @@ -53,9 +54,13 @@
    1.12  
    1.13  	@Override
    1.14  	public PreparedStatement prepareStatement(Connection c) throws SQLException {
    1.15 -		buildPattern();
    1.16 -		placeParametersAndUpdateQuery();
    1.17 -		logPossiblyMissingParameters();
    1.18 +		try {
    1.19 +			buildPattern();
    1.20 +			placeParametersAndUpdateQuery();
    1.21 +			logPossiblyMissingParameters();
    1.22 +		} catch (PatternSyntaxException e) {
    1.23 +			throw new SQLException("Name prefix „" + namePrefix + "“ or suffix „" + nameSuffix + "“ contain a wrong regular expression. " + e.getLocalizedMessage(), e);
    1.24 +		}
    1.25  		return c.prepareStatement(updatedQuery.toString());
    1.26  	}
    1.27