Thank you @r_gigante for the reply!
Sorry if the intent is unclear: this self-contained script was something I came up with last night to demonstrate an issue I'm having in my plugin which is too many scripts to post to the forums. Since the user can't select an object after the script is running, I added that catch to make sure an object was selected to show what was going wrong.
My Goal
I am trying to save a link to a scene object and its matrix to a hyperfile so the user can load the hyperfile in another session and restore the link to the object so that I can apply the saved matrix. I don't need the object itself.
Update
I updated the original script's GetLink() method to pass a reference to the active document, but that did not solve the issue.