Resolved the exception error problem that python3 caught cx_oracle throwing

  • 2020-12-22 17:43:37
  • OfStack

Recently, I was using python to write a program to monitor oracle, but I didn't use exception handling. Then, some errors in daily monitoring generally threw database connection exceptions, resulting in the failure to timely locate the problem in subsequent processing.

So I took some time in the morning to look at python3's exception handling for cx_oracle.

Instead, I just want to catch the specific ora- information when python throws an oracle error.

It's easy to write it down here for later use.


try:
  oracle_check(dbname)
except cx_Oracle.DatabaseError as msg:
  print(msg)

In addition, in python3, if there are multiple items after except, () should be added, which is the difference from python2.


Related articles: