input: Write a function to rewrite the given SQL query in Python. The function should connect to a SQLite database named 'movies.db', execute the query to select all rows from the 'Movies' table where the 'category' is 'horror', and print each row of the result. If the database connection or query execution fails, the function should handle the exception gracefully and print an error message.
  
  import sqlite3
  
  def rewrite_sql_query():
      try:
          conn = sqlite3.connect('movies.db') 
          cursor = conn.cursor()
  
          cursor.execute("SELECT * FROM Movies WHERE category = 'horror'")
  
          result = cursor.fetchall()
          for row in result:
              print(row)
  
          conn.close()
      except Exception as e:
          print(f"An error occurred: {e}")
  
  assert rewrite_sql_query() is None
output: def rewrite_sql_query():
      try:
          conn = sqlite3.connect('movies.db') 
          cursor = conn.cursor()
  
          cursor.execute("SELECT * FROM Movies WHERE category = 'horror'")
  
          result = cursor.fetchall()
          for row in result:
              print(row)
  
          conn.close()
      except Exception as e:
          print(f"An error occurred: {e}")