input: Write a function to create a Python API that fetches data from an SQL database and presents the data in the form of a JSON. The function should initialize a Flask app, define a route to fetch all user data from the 'users' table in the database, and return the data as a JSON. If the database is empty or inaccessible, the function should handle the exception gracefully.
  
  assert fetch_user_data() == "[]"
  
output: def fetch_user_data():
      from flask import Flask, jsonify
      import sqlite3
  
      app = Flask(__name__)
  
      @app.route('/users', methods=['GET'])
      def get_users():
          try:
              conn = sqlite3.connect('database.db')
              cursor = conn.cursor()
              cursor.execute("SELECT * FROM users")
              rows = cursor.fetchall()
              users = [{"id": row[0], "name": row[1], "email": row[2]} for row in rows]
              return jsonify(users)
          except sqlite3.Error:
              return jsonify([])
          finally:
              if conn:
                  conn.close()
  
      with app.app_context():
          return get_users().get_data(as_text=True)