Catching null pointer exceptions so as to not mask the real error.

If result is null, that means something failed during I/O. This could be a timeout or socket exception etc... however if we blindly close the connection, it will invariably throw a null pointer exception thus the original (real) problem is never reported. This prevents such behavior.