Add: parameterKey field to ParameterParseException (docstrings included)
This commit is contained in:
+14
-1
@@ -2,13 +2,26 @@ package ch.unibas.dmi.dbis.cs108.casono.server.network.parser;
|
||||
|
||||
/** Exception thrown when a parameter value cannot be converted to the requested type. */
|
||||
public class ParameterParseException extends RuntimeException {
|
||||
private final String parameterKey;
|
||||
|
||||
/**
|
||||
* Creates a new parse exception with a root cause.
|
||||
*
|
||||
* @param message human-readable description of the parsing failure
|
||||
* @param parameterKey key for whose value the error occured
|
||||
* @param cause original exception thrown during parsing
|
||||
*/
|
||||
public ParameterParseException(String message, Throwable cause) {
|
||||
public ParameterParseException(String message, String parameterKey, Throwable cause) {
|
||||
super(message, cause);
|
||||
this.parameterKey = parameterKey;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the missing parameter key.
|
||||
*
|
||||
* @return key for whose value the error occured
|
||||
*/
|
||||
public String getParameterKey() {
|
||||
return parameterKey;
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -56,7 +56,7 @@ public class RequestParameterAccessor {
|
||||
try {
|
||||
return parser.parse(value);
|
||||
} catch (Exception e) {
|
||||
throw new ParameterParseException("Error while parsing with specified parser", e);
|
||||
throw new ParameterParseException("Error while parsing '" + key + "' with specified parser", key, e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -94,7 +94,7 @@ public class RequestParameterAccessor {
|
||||
try {
|
||||
return parser.parse(value);
|
||||
} catch (Exception e) {
|
||||
throw new ParameterParseException("Error while parsing with specified parser", e);
|
||||
throw new ParameterParseException("Error while parsing '" + key + "' with specified parser", key, e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user