Advertisement
mayankjoin3

Untitled

May 11th, 2024
1,148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.39 KB | None | 0 0
  1. import logging
  2.  
  3. # Configure logging
  4. logging.basicConfig(filename='errors.txt', level=logging.ERROR, filemode='a')
  5.  
  6. def separator():
  7.     with open("errors.txt", "a") as file:
  8.         file.write("\n*********\n\n")
  9.  
  10. try:
  11.     # Code that may raise an exception
  12.     # ...
  13.     x = 10 / 0  # Example division by zero error
  14. except Exception as e:
  15.     logging.exception(str(e))
  16.     separator()
  17.  
  18.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement