begin
# code that raises exception
rescue StandardError => e
puts e.backtrace
end
Другие ответы, большие для первой половины Вашего вопроса...
Вот сжатый ответ на вторую половину.
через https://devcenter.heroku.com/articles/renaming-apps#updating-git-remotes
git remote rm heroku
heroku git:remote -a name-of-heroku-app