Quick confirmation on check for substring in Python 3.6
Question:
I write my code in Python 3.8.9 with this line, which works:
try:
...
except Exception as e:
if "AlreadyExistsException" in e:
When deploying it in a Python 3.6 environment, I get this error:
TypeError: argument of type 'AlreadyExistsException' is not iterable
Could someone help confirming that the operation to check for the existence of a substring AlreadyExistsException
in the error string e
like above does not work in Python 3.6? I don’t have Python 3.6 to test this out and too hesitated to install it to test this error. And if this is true, what is a workable way to check for substring in Python 3.6?
Answers:
The correct way to check for a specific type of Exception
would be:
try:
...
except AlreadyExistsException as e:
# do something in response to this specific exception
...
except (SomeOtherException, AndAnotherException) as e:
# do something in response to those specific exceptions
...
I write my code in Python 3.8.9 with this line, which works:
try:
...
except Exception as e:
if "AlreadyExistsException" in e:
When deploying it in a Python 3.6 environment, I get this error:
TypeError: argument of type 'AlreadyExistsException' is not iterable
Could someone help confirming that the operation to check for the existence of a substring AlreadyExistsException
in the error string e
like above does not work in Python 3.6? I don’t have Python 3.6 to test this out and too hesitated to install it to test this error. And if this is true, what is a workable way to check for substring in Python 3.6?
The correct way to check for a specific type of Exception
would be:
try:
...
except AlreadyExistsException as e:
# do something in response to this specific exception
...
except (SomeOtherException, AndAnotherException) as e:
# do something in response to those specific exceptions
...