Added exception handling.

The script was crashing and I didn’t know why (the Pi was losing its
wifi connection, it turns out), so I added exception handling to trap
issues like this.