frjaeger220 / google-guice

Automatically exported from code.google.com/p/google-guice
Apache License 2.0
0 stars 0 forks source link

ConfigurationException needs to be made public and documented in @throws #68

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
For methods like Injector.getProvider() or getInstance(), in the general
case it's impossible to know ahead of time whether they will succeed or
throw a ConfigurationException.  Yet ConfigurationException is unchecked
and is not a publicly exposed type in the API, making the whole situation
darn awkward.

Technically I think this should have been a checked exception, but too late
to fix that now.  The fix we can make is to make the exception type public
and document it in the @throws clauses of the relevant methods.

And we may as well name it appropriately before it becomes visible.  The
exception doesn't happen due to any configuration problem, it happens
because you ask guice for a key that it can't resolve all the way to a
provider.  so, ResolutionException, ProviderResolutionException,
CantResolveProviderException, blah blah blah... ideas?

Original issue reported on code.google.com by kevin...@gmail.com on 15 Mar 2007 at 4:41

GoogleCodeExporter commented 9 years ago
Oh, and related, it would be nice to have an Injector.canProvide(Key) method so 
you
wouldn't have to try/catch.  Can we add methods to this interface, or are we 
actually
concerned about breaking the code of people who may, for whatever unfathomable
reason, be implementing the Injector interface themselves?

Original comment by kevin...@gmail.com on 15 Mar 2007 at 4:42

GoogleCodeExporter commented 9 years ago
NoSuchProviderException, ProviderNotFoundException?

Original comment by dha...@gmail.com on 15 Mar 2007 at 6:21

GoogleCodeExporter commented 9 years ago

Original comment by kevin...@gmail.com on 19 Mar 2007 at 6:33

GoogleCodeExporter commented 9 years ago
+1.  How about InjectorException?

Original comment by bslesinsky on 28 Jun 2007 at 4:53

GoogleCodeExporter commented 9 years ago
CreateException or somthing straightforward like that. Can't create the thing, 
simple. I'd reflect what could happen not how it happens, users can read that 
in the 
exception message.

Original comment by robbie.v...@gmail.com on 13 Aug 2007 at 7:33

GoogleCodeExporter commented 9 years ago

Original comment by limpbizkit on 30 May 2008 at 6:54

GoogleCodeExporter commented 9 years ago
Jersey (JAX-RS implementation) needs Injector.canProvide(Key) because it tries 
using
Guice on its own classes and expects it to return null if it cannot inject them.

Original comment by gili.tza...@gmail.com on 2 Oct 2008 at 2:59

GoogleCodeExporter commented 9 years ago
Guice 2.0 will provide this using Injector.getBinding(Key<T>), which returns 
null, if
there is no binding. Otherwise you can invoke Binding.<T>getProvider().get() to
retrieve an instance.

Original comment by sven.lin...@gmail.com on 3 Oct 2008 at 11:47

GoogleCodeExporter commented 9 years ago
ConfigurationException is now a public RuntimeException.

Aside...
The best way to test if a Key is bound is via
   Injector.getBindings().containsKey(Key).

The getBinding API has changed since Guice 1.0 to not return null. I just 
updated the Javadocs. It hasn't 
actually returned null for quite some time (probably right after the 1.0 
snapshot was cut). This is also 
documented on the Guice2 wiki: http://code.google.com/p/google-guice/wiki/Guice2

Original comment by limpbizkit on 2 Nov 2008 at 5:21