Use try/catch instead of typeof check