Создайте пользовательское исключение.Если пользователь библиотеки должен перехватить это исключение, он может импортировать его.
Например, взять pickle.PicklingError
:
>>> import pickle
>>> pickle.dumps(type(None))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python27\lib\pickle.py", line 1374, in dumps
Pickler(file, protocol).dump(obj)
File "C:\Python27\lib\pickle.py", line 224, in dump
self.save(obj)
File "C:\Python27\lib\pickle.py", line 286, in save
f(self, obj) # Call unbound method with explicit self
File "C:\Python27\lib\pickle.py", line 748, in save_global
(obj, module, name))
pickle.PicklingError: Can't pickle <type 'NoneType'>: it's not found as __builtin__.NoneType
>>> try:
... pickle.dumps(type(None))
... except pickle.PicklingError:
... print 'Oops.'
...
Oops.