def _mk_lcberr(rc, name=None, default=CouchbaseException, docstr="", extrabase=[]): """ Create a new error class derived from the appropriate exceptions. :param int rc: libcouchbase error code to map :param str name: The name of the new exception :param class default: Default exception to return if no categories are found :return: a new exception derived from the appropriate categories, or the value supplied for `default` """ categories = C._get_errtype(rc) if not categories: return default bases = extrabase[::] for cat, base in _LCB_ERRCAT_MAP.items(): if cat & categories: bases.append(base) if name is None: name = "LCB_0x{0:0X} (generated, catch: {1})".format( rc, ", ".join(x.__name__ for x in bases)) d = {'__doc__': docstr} if not bases: bases = [CouchbaseException] return type(name, tuple(bases), d)
def categories(self): """ Gets the exception categories (as a set of bits) """ return C._get_errtype(self.rc)