We're sorry but this app doesn't work properly without JavaScript enabled. Please enable it to continue.

This lesson's interactive features are locked, please to keep using them

Throwing Errors

Sometimes errors are thrown implicitly by the JavaScript runtime, as we saw in past examples. But sometimes we need to throw errors ourselves explicitly. The throw statement is how we do it:

throw new Error("something went wrong");

It's worth mentioning that JavaScript will allow you to throw anything you want, not just error objects:

throw "something went wrong";

But for consistency and maintainability, I recommend always throwing error objects.

Assignment

Textio is integrating with an external nano-messaging service, Xirpy, that strictly enforces a 70-character limit on incoming messages. Complete the sendMessage function, which takes a msg string: