Adjust exception catch syntax to support future versions of Python