Bitpath

Lesson 2 · Unit 03

Reading errors

The message says what, the stack trace says where

12 exercisesabout 3 min

What you practise

  • Stack traces from the bottom up (or the top down), the usual errors in each language and what causes them, the line reported vs the line at fault

Try a question from this lesson

Pick one

A program crashes with this report. Which function was running at the moment the error happened?

Traceback (most recent call last):
  File "shop.py", line 14, in <module>
    checkout(cart)
  File "shop.py", line 8, in checkout
    total = total_price(cart)
  File "shop.py", line 3, in total_price
    total += item["price"]
KeyError: 'price'
shop.js:3
  for (const item of cart.items) {
                          ^
TypeError: cart.items is not iterable
    at totalPrice (shop.js:3:27)
    at checkout (shop.js:8:10)
    at Object.<anonymous> (shop.js:14:1)
shop.ts:3
  for (const item of cart.items) {
                          ^
TypeError: cart.items is not iterable
    at totalPrice (shop.ts:3:27)
    at checkout (shop.ts:8:10)
    at Object.<anonymous> (shop.ts:14:1)
Hint

Find the error message, then the frame printed right next to it.

The idea

Concept cards are short on purpose. In the app they appear between questions, after you have met the idea.

Concept

Two parts of an error

An error report has two parts.

The message says what went wrong: an error type and a detail.

The stack trace says where: the line that failed, then the line that called it, then the caller of that.

Read the message first. Then find the first frame that belongs to your own code.

Python noteIn Python the message is the last line, and the frame where it happened is directly above it. Read from the bottom up.

JavaScript noteIn Node the message comes first and the frame where it happened is the first at line under it. Read from the top down.

TypeScript noteTypeScript runs as JavaScript, so traces read top down. With source maps the frames point at your .ts lines.

10 more exercises in the app

  • 4× multiple choice
  • 1× match the pairs
  • 2× type the answer
  • 1× true or false
  • 1× fill the blanks
  • 1× order the lines

Bitpath is an iOS app in development. Join the waitlist and you get one email when it is ready to try.

One email when Bitpath is ready to try. Nothing else. Privacy