TDengine/docs/examples/python/handle_exception.py

24 lines
599 B
Python
Raw Permalink Normal View History

2024-11-19 09:36:20 +00:00
import taosrest
import os
url = os.environ["TDENGINE_CLOUD_URL"]
token = os.environ["TDENGINE_CLOUD_TOKEN"]
2022-08-24 10:33:10 +00:00
try:
2024-11-19 09:36:20 +00:00
conn = taosrest.connect(url=url, token=token)
2022-08-24 10:33:10 +00:00
conn.execute("CREATE TABLE 123") # wrong sql
2024-11-19 09:36:20 +00:00
except taosrest.Error as e:
2022-08-24 10:33:10 +00:00
print(e)
print("exception class: ", e.__class__.__name__)
print("error number:", e.errno)
print("error message:", e.msg)
except BaseException as other:
print("exception occur")
print(other)
# output:
2024-11-19 09:36:20 +00:00
# [0x2600]: syntax error near "123"
# exception class: ConnectError
# error number: 9728
# error message: syntax error near "123"