XD blog

blog page

exception


2014-07-01 Pywin32 does not find its DLL

I recently needed to install pywin32 because of nbconvert. However, when importing win32api, it produces an exception (unable to find some DLL). To fix it, the following path <python>Lib/site-packages/pywin32_system32 must be added to environment variable PATH. But I did not want to do that but I'm using several Python version at the same time so I needed to fix it while running my script which I did below.


more...

2013-12-06 Extend the exception stack in Python

Most of the time, message given by exception are not enough precise to quickly understand the error. To add more information, I used to catch it and throw a new one:

try :
    # something
except Exception as e :
    message = "my message with more information \n" + str(e)
    raise Exception(message) 

However, it is possible to do this:

try :
    # something
except Exception as e :
    message = "my message with more information"
    raise Exception(message) from e

It does not break the exception stack as before. The new exception is just added to it.


more...

2013-08-12 Exceptions in Python

when raising an exception, we might be tempted by using the type Exception. But this type also gives information on the error. Python has a list of standard exceptions with a meaningful name: standard exceptions. They should be used.


Xavier Dupré