Attempting to close db during a transaction (iOS)

Hi,

I need to delete the database in some cases, but I am getting the exception when I a try to do it… Also I am not sure why the catch block is not catching the exception, the app is just crushing with:

*** Terminating app due to uncaught exception ‘NSInternalInconsistencyException’, reason: ‘Attempting to close db during a transaction’

func deleteDatabase() {
        do {
            try database.deleteDatabase()            
        } catch  {
            print("Delete database error!")
        }
    }

Any way how to delete database safely?