Using a try catch to prevent TypeErrors