Fredo does not know he is about to be killed.
The "hail mary" thing is only to make the scene more powerful. If he had told Tony that to catch a fish he always lets say sang a Johnny Fontaine song, then he would have died singing. It's only to make the scene more sad that he dies praying, Unknown that he's about to be shot.
I don't know anyone can think Fredo deserved to die.