Add try{} catch{} statement to catch the type error