

0 / 2 embers
0 / 3000 xp
click for more info
Complete a lesson to start your streak
click for more info
Difficulty: 3
click for more info
Not enough gems
Cost: 6 gems
1: Error Object
incomplete
2: Handling Errors
incomplete
3: Finally
incomplete
4: Throwing Errors
incomplete
5: When to try/catch
incomplete
This lesson's interactive features are locked, please to keep using them
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.
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: