Skip to content

Commit 06dc474

Browse files
committed
gpclient: Adding TypeMismatchException
1 parent 9aa4024 commit 06dc474

3 files changed

Lines changed: 40 additions & 2 deletions

File tree

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/**
2+
* Copyright information and license terms for this software can be
3+
* found in the file LICENSE.TXT included with the distribution.
4+
*/
5+
package org.epics.gpclient;
6+
7+
/**
8+
* Exception thrown when a channel or an expression cannot return the type
9+
* requested.
10+
*
11+
* @author carcassi
12+
*/
13+
public class TypeMismatchException extends RuntimeException {
14+
15+
/**
16+
* Creates a new exception with the given message.
17+
*
18+
* @param message the message
19+
*/
20+
public TypeMismatchException(String message) {
21+
super(message);
22+
}
23+
24+
/**
25+
* Creates a new exception with the given message and cause.
26+
*
27+
* @param message the message
28+
* @param cause the cause
29+
*/
30+
public TypeMismatchException(String message, Throwable cause) {
31+
super(message, cause);
32+
}
33+
34+
35+
36+
}

gpclient/gpclient-core/src/main/java/org/epics/gpclient/datasource/DataSourceTypeSupport.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import java.util.Collection;
99
import java.util.List;
1010
import org.epics.gpclient.ReadCollector;
11+
import org.epics.gpclient.TypeMismatchException;
1112

1213
/**
1314
* The type support for a datasource. This optional class is provided to help
@@ -42,7 +43,7 @@ protected <C, T extends DataSourceTypeAdapter<? super C,?>> T find(Collection<T>
4243
}
4344

4445
if (matchedConverters.size() != 1) {
45-
throw new IllegalStateException(formatMessage(cache, connection, matchedConverters));
46+
throw new TypeMismatchException(formatMessage(cache, connection, matchedConverters));
4647
}
4748

4849
return matchedConverters.get(0);

gpclient/gpclient-core/src/main/java/org/epics/gpclient/datasource/MultiplexedChannelHandler.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import java.util.logging.Level;
1111
import java.util.logging.Logger;
1212
import org.epics.gpclient.ReadCollector;
13+
import org.epics.gpclient.TypeMismatchException;
1314
import org.epics.gpclient.WriteCollector;
1415

1516
/**
@@ -197,7 +198,7 @@ public void updateCache(ReadCollector cache, Object connection, Object message)
197198
if (message == null || cache.getType().isInstance(message)) {
198199
cache.updateValue(message);
199200
} else {
200-
throw new IllegalArgumentException("Payload " + message + " does not match " + cache.getType().getSimpleName());
201+
throw new TypeMismatchException("Payload " + message + " does not match " + cache.getType().getSimpleName());
201202
}
202203
}
203204
};

0 commit comments

Comments
 (0)