Python modules often have their own exceptions. I often find myself wanting to import those exceptions to be able to properly catch them (properly as in not just cacthing Exception and hoping for the best).
However, I often find myself spending time to figure out exactly where in a module the exceptions are located, or if they're imported from another module, etc. I'm curious if there's a general way to find this out, i.e. given SomeModulespecificException is there a simple way to figure out how to import it?
Here's an example from the multiprocessing module:
import multiprocessing
q = multiprocessing.Queue()
q.get_nowait()
The above code raises an Empty Exception. In this case, I found out from this answer that the exception is imported from the Queue module, so in this particular case, you need from Queue import Empty to import the exception.
Is there an easy way to figure this out in the general case?
Exception as ewhile developing and thenprint(type(e))to see what I should actually be catching.