If the factory returns null, a FrameworkEvent.ERROR will be fired with a ServiceException.FACTORY_ERROR.
If the factory throws an exception, a FrameworkEvent.ERROR will be fired with a ServiceException.FACTORY_EXCEPTION. The exception thrown from the factory will be the cause of the ServiceException. In both cases, BundleContext.getService will return null to the caller. The caller will not be thrown an exception. So I would let the exception propagate from the factory and let the framework handle it. -- BJ Hargrave Senior Technical Staff Member, IBM OSGi Fellow and CTO of the OSGi Alliance [email protected] office: +1 386 848 1781 mobile: +1 386 848 3788 From: Holger Hoffstätte <[email protected]> To: [email protected] Date: 2011/01/26 07:13 Subject: [osgi-dev] ServiceFactory vs. exceptions Sent by: [email protected] Hi, a newbie question about ServiceFactory. I cannot seem to find any guideline what the behaviour is supposed to be when the details of getService() fail and I have an exception on my hands inside the factory. Should it: 1) propagate the exception and let the framework handle it - if so, how? will it turn the exception into a returned null to ServiceTracker, BundleContext.getService() etc.? 2) return null itself 3) do something else? So far I could find all three approaches "in the wild", which tells me there's something missing. ServiceException has 2 types for factory failures, but it's not clear from either the docs or the spec who creates this exception exactly when or why. To quote: "..the framework or user code.." :-) Will be grateful for advice or RTFM pointers. Holger _______________________________________________ OSGi Developer Mail List [email protected] https://mail.osgi.org/mailman/listinfo/osgi-dev
_______________________________________________ OSGi Developer Mail List [email protected] https://mail.osgi.org/mailman/listinfo/osgi-dev
