input: Write a function to generate an HTML table displaying information about the top 10 bestselling books in a specific genre from a given database. The function should connect to the database, retrieve the data, and format it into an HTML table. If the database connection fails, the function should raise an exception.
  assert generate_html_table("books.db", "Fantasy") == """<table>
  <tr><th>Title</th><th>Author</th><th>Genre</th><th>Sales</th></tr>
  <!-- Assuming the retrieved data is correct -->
  <tr><td>Title1</td><td>Author1</td><td>Fantasy</td><td>100</td></tr>
  <tr><td>Title2</td><td>Author2</td><td>Fantasy</td><td>90</td></tr>
  <tr><td>Title3</td><td>Author3</td><td>Fantasy</td><td>80</td></tr>
  <tr><td>Title4</td><td>Author4</td><td>Fantasy</td><td>70</td></tr>
  <tr><td>Title5</td><td>Author5</td><td>Fantasy</td><td>60</td></tr>
  <tr><td>Title6</td><td>Author6</td><td>Fantasy</td><td>50</td></tr>
  <tr><td>Title7</td><td>Author7</td><td>Fantasy</td><td>40</td></tr>
  <tr><td>Title8</td><td>Author8</td><td>Fantasy</td><td>30</td></tr>
  <tr><td>Title9</td><td>Author9</td><td>Fantasy</td><td>20</td></tr>
  <tr><td>Title10</td><td>Author10</td><td>Fantasy</td><td>10</td></tr>
  </table>"""
  assert generate_html_table("nonexistent.db", "Sci-Fi") == Exception("Connection to database failed")
output: 
  try:
      import sqlite3
      conn = sqlite3.connect(db_name)
      cursor = conn.cursor()
      cursor.execute("SELECT Title, Author, Genre, Sales FROM books WHERE Genre=? ORDER BY Sales DESC LIMIT 10", (genre,))
      rows = cursor.fetchall()
      conn.close()
      html_table = "<table>\n<tr><th>Title</th><th>Author</th><th>Genre</th><th>Sales</th></tr>\n"
      for row in rows:
          html_table += f"<tr><td>{row[0]}</td><td>{row[1]}</td><td>{row[2]}</td><td>{row[3]}</td></tr>\n"
      html_table += "</table>"
      return html_table
  except sqlite3.Error as e:
      raise Exception("Connection to database failed")
  