Locked learning resources

Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Locked learning resources

This lesson is for members only. Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

When Things Go Wrong: Errors and Debugging (Summary)

You’ve finished When Things Go Wrong: Errors and Debugging. First, the season log crashed, and you read the report from the top: formatRun() threw a TypeError. The next line down led to printSeason(), whose loop ran one pass too far. The fix went there, on the bug line.

Next, checkRun() threw errors that name the run. Each one climbed out to the catch in the import loop, which reported the bad run and skipped it. Last, Priya’s total came out ten kilometers short, with no error. Your debugging card held the expected and actual totals, and a hypothesis a check could prove wrong. Halving the runs left run 7, whose runner name ends in a space.

In This Course, You Learned How To

  • Read a stack trace to find where a failure starts
  • Catch only the errors your code can handle
  • Throw errors with useful messages, and catch them at the right level
  • Track down a wrong result with a method instead of guessing
  • Build Ruth’s season log, and explain how it works

Things to Remember

Locked learning resources

Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Already a member? Sign-In

Locked learning resources

The full lesson is for members only. Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Already a member? Sign-In

00:00 You’ve finished When Things Go Wrong: Errors and Debugging. In this course, you learned to read a stack trace to find where a failure starts. To catch only the errors your code can handle.

00:13 To throw errors with useful messages, and catch them at the right level. To track down a wrong result with a method instead of guessing. And you built Ruth’s season log, and explained how it works.

00:27 First, the season log crashed, and you read the report from the top: formatRun() threw a TypeError. The next line down led to printSeason(), whose loop ran one pass too far.

00:38 The fix went there, on the bug line. Next, checkRun() threw errors that name the run. Each one climbed out to the catch in the import loop, which reported the bad run and skipped it.

00:52 Last, Priya’s total came out ten kilometers short, with no error. Your debugging card held the expected and actual totals, and a hypothesis a check could prove wrong.

01:03 Halving the runs left run 7, whose runner name ends in a space.

01:09 Things to remember. Read an error from the top, down to your own code. The crash line isn’t always the bug line. Wrap only what can fail, and rethrow what you can’t handle.

01:23 Some bad values don’t throw, so check them. Throw where the problem is found, and catch where the code can respond. And for a wrong result, write down expected and actual first.

01:37 RealJS has reference pages on JavaScript’s error types, and on the try and throw statements.

01:45 Thanks for watching.

Become a Member to join the conversation.