Chrome Extension

Get exception text in python

To get the exception text thrown by python code, you can use the below code.
  result = 3/0 #this will throw error
except Exception as e:
  print("Repr : " + repr(e)) # Use repr to get error
  print("Error : " + str(e)) # Use str to get error
Best JSON Validator, JSON Tree Viewer, JSON Beautifier at same place. Check how cool is the tool
Repr : ZeroDivisionError('division by zero',)
Error : division by zero

We are getting exception thrown by dividing a number by 0. We are using repr and str to print out the exception text.

Was this helpful?
Join Devsheet Ask a Question