Use (msg != NULL) instead of caught variable and remove the caught
variable.

Suggested by mpi.