Replace exception handling with an if() check for null references