hacksong / jsonrpc4j

Automatically exported from code.google.com/p/jsonrpc4j
0 stars 0 forks source link

java.lang.reflect.UndeclaredThrowableException instead of java.net.ConnectException #22

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Write simple service interface with one method "String echo(String s)" 
without any throwable exceptions.
2. Use ProxyUtil.createProxy with JsonRpcHttpClient to create a proxy to this 
inerface.
3. Execute myService.echo("test"); with no server running which can handle 
JsonRpc Http request.

What is the expected output?
java.net.ConnectException expected. Also expected that I must declare try-catch 
as that is checked exception.

What do you see instead?
java.lang.reflect.UndeclaredThrowableException
Caused by: java.net.ConnectException: Connection refused

What version of the product are you using? On what operating system?
0.23

Please provide any additional information below.
I fixed that by adding java.net.ConnectException to throws declaration on each 
method of my service (String echo(String s) throws ConnectException). But is it 
really correct solution?

Original issue reported on code.google.com by xak2...@gmail.com on 20 Apr 2012 at 12:39

GoogleCodeExporter commented 9 years ago
You're wrong in expecting "ConnectException" from a Proxy.  The basic rules of 
a Proxy is that it will only throw Exceptions defined by the interface that it 
is proxying.  All other exceptions are thrown as an 
UndeclaredThrowableException.

Original comment by brian.di...@gmail.com on 21 May 2012 at 8:16

GoogleCodeExporter commented 9 years ago

Original comment by brian.di...@gmail.com on 26 May 2012 at 2:42