Try catch statement to prevent TypeError