commit 9e3a03f1086fb70869d403933938d77e30bc52fc
parent ff520d00acc268ad4dad8499de6767a5bee370f7
Author: Dan Callaghan <djc@djc.id.au>
Date: Wed, 7 Oct 2009 20:30:49 +1000
better error reporting
Diffstat:
2 files changed, 14 insertions(+), 5 deletions(-)
diff --git a/src/main/antlr3/au/com/miskinhill/rdftemplate/selector/Selector.g b/src/main/antlr3/au/com/miskinhill/rdftemplate/selector/Selector.g
@@ -58,14 +58,19 @@ selector returns [Selector<?> result]
| { result = new NoopSelector(); }
)
( '#'
- adaptationName=XMLTOKEN { adaptationClass = adaptationResolver.getByName($adaptationName.text); }
+ adaptationName=XMLTOKEN
+ {
+ adaptationClass = adaptationResolver.getByName($adaptationName.text);
+ if (adaptationClass == null)
+ throw new InvalidSelectorSyntaxException("No adaptation named " + $adaptationName.text);
+ }
( '('
startIndex=INTEGER {
try {
adaptation = adaptationClass.getConstructor(Integer.class)
.newInstance(Integer.parseInt($startIndex.text));
} catch (Exception e) {
- throw new RuntimeException(e);
+ throw new InvalidSelectorSyntaxException(e);
}
}
')'
@@ -73,7 +78,7 @@ selector returns [Selector<?> result]
try {
adaptation = adaptationClass.newInstance();
} catch (Exception e) {
- throw new RuntimeException(e);
+ throw new InvalidSelectorSyntaxException(e);
}
}
)
diff --git a/src/main/java/au/com/miskinhill/rdftemplate/selector/InvalidSelectorSyntaxException.java b/src/main/java/au/com/miskinhill/rdftemplate/selector/InvalidSelectorSyntaxException.java
@@ -6,8 +6,12 @@ public class InvalidSelectorSyntaxException extends RuntimeException {
private static final long serialVersionUID = 5805546105865617336L;
- public InvalidSelectorSyntaxException(RecognitionException e) {
- super(e);
+ public InvalidSelectorSyntaxException(Throwable cause) {
+ super(cause);
+ }
+
+ public InvalidSelectorSyntaxException(String message) {
+ super(message);
}
}