Before using the value of a return of a function, I want to check if the value is useable. So what I have is more or less the following:
def get_module():
import foo
return foo
def do_something():
try:
module = get_module()
except:
print "error"
module.bar()
Unfortunately, it seems to me that this never raises an exception. In particular, I want to check (a) that the module was transferred correctly and (b) that the module is one of three possible modules.
I know I can check through if-statements, but I feel that exception handing is ought to be the correct way.
foodoesn't exist. Otherwiseget_modulewill raiseImportError(which you should catch explicitly instead of a bareexcept)