added null checks for exception message