From 96bb97778b8218eb209214ba84174c38693438f2 Mon Sep 17 00:00:00 2001 From: "mhammond%skippinet.com.au" Date: Thu, 7 Mar 2002 12:01:38 +0000 Subject: [PATCH] Provide a nicer exception when an unknown contract ID is attempted to be used. Not part of the build. --- extensions/python/xpcom/components.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/extensions/python/xpcom/components.py b/extensions/python/xpcom/components.py index d321f3bf6a6..7766dc00ffd 100644 --- a/extensions/python/xpcom/components.py +++ b/extensions/python/xpcom/components.py @@ -159,7 +159,14 @@ class _Class: raise AttributeError, "%s class has no attribute '%s'" % (self.contractid, attr) def createInstance(self, iid = None): import xpcom.client - return xpcom.client.Component(self.contractid, _get_good_iid(iid)) + try: + return xpcom.client.Component(self.contractid, _get_good_iid(iid)) + except xpcom.COMException, details: + import nsError + # Handle "no such component" in a cleaner way for the user. + if details.errno == nsError.NS_ERROR_FACTORY_NOT_REGISTERED: + raise xpcom.COMException(details.errno, "No such component '%s'" % (self.contractid,)) + raise # Any other exception reraise. def getService(self, iid = None): return serviceManager.getServiceByContractID(self.contractid, _get_good_iid(iid))