How to Raise and Handle Exceptions in JavaScript
Quick start with try, catch, throw, and finally

There are cases when functions fail due to an unexpected problem. A common practice is to throw exceptions in these cases and have a part of the code handling them. This is what JavaScript does.
For example, trying to change a frozen object results in an exception. Here is an…