Можно использовать try...catch.
try...catch
javascript
Register or sign in to get access to full answers for all questions from the question bank.