Unify message receiving code and handle various networking exceptions.