Switch from exception handling to if checking