users@hk2.java.net

Re: Question about Provider

From: John Wells <john.wells_at_oracle.com>
Date: Fri, 18 Apr 2014 07:52:15 -0400

I guess I don't fully understand your question.

If A depends on B which depends on C and C is created with a
Factory.provide method, and that provide method throws an exception than
anyone looking up A, B or C will get a MultiException. The
multi-exception may contain many exceptions, including the one throws
from the Factory provide method, but it will also contain exceptions
saying things like "while trying to inject B we could not create C".

HK2 does not currently send events for things like this, as we tend to
just collect all the exceptions in one multi-exception as it goes up the
chain to the original lookup call. Since hk2 is a "demand" driven
system this seemed sufficient to us.

But I'm also not 100% sure I understand your question. Perhaps you
could post more of your code to help me understand the request?

Thanks

On 4/17/2014 6:12 PM, Mingtao Zhang wrote:
>
> Hi,
>
> Have a question about exception handling in HK2.
>
> I have C inject into B then inject into A. So the constructor looks like
>
> @Inject
>
> A(B)
>
> @Inject
>
> B(C)
>
> C has a provider (Factory<C>), I am able to catch an exception inside
> the .provide() method. If I don't catch it, looks like HK2 is ignoring
> the exception.
>
> My target is to log Provider generated exceptions in a central place.
> I have looked at
> https://hk2.java.net/2.3.0-b04/events.html#The_Default_TopicDistributionService,
> which requires a "event firing".
>
> Is there a good way to do that?
>
> Thanks in advance!
>
> Best Regards,
>
> Mingtao
>