What you should do is wait a couple of seconds (the time it requires the ball to shake three times and say Gotcha - no more) Then restart your game. Contrary to the other answer this is not an exploit, simply the visual bit of the game has frozen, but the inner mechanics are still working, and it's still talking to the server. This is where the term Schrödinger's Pokemon comes from - until you've restarted the game and checked, the Pokemon is both caught and not.
There is no guarantee that this will work. It depends on weather or not the pokemon would have stayed in the ball or not in the first place. If you would hace caught the Pokemon, with the game glitching like this or not, you will catch it, if it would have escaped the ball there's nothing you could do.
Generally it's a good idea not to attempt catching any rear pokemon if the white ball is spinning alot. This means its trying to talk to the server alot due to slow response time from said server.
Every now and then check this site if everything is green, you're good to go and shouldn't be having problems.