Fix exception handling in networking code