Now that we know what information we can get from an error stack trace, let’s take a look at an example.
Using this stack trace, let’s answer three questions you should ask yourself every time you want to debug an error:
- In what line did the error occur? You can almost always find this information on the first line of the stack trace in the following format
<file path>/<file name>:<line number>. In this example, the location is
app.js:1. This means that the error was thrown in the file named
- What type of error was thrown? The first word on the fifth line of the stack trace is the type of error that was thrown. In this case, the type of error was
ReferenceError. We will discuss this error type in the next exercise.
- What is the error message? The rest of the fifth line after the error type provides an error message, describing what went wrong. In this case, the description is
myVariable is not defined.
You might notice in this example we skipped explaining a few lines in the stack trace and only included the beginning of the stack trace. A large part of debugging errors is recognizing which pieces of information are useful and which ones aren’t. For now, you will succeed by focusing on just the first and fifth lines of your error stack traces.
Near the beginning of the text file in the code editor, you will find an example stack trace. On line 14 of the text file, fill in the name of the file throwing the error in this stack trace.
If you are unsure how to fill in the answer, feel free to check out the hint.
On line 16 of the text file, fill in the line number throwing the error in the example stack trace.
On line 18 of the text file, fill in the type of the error being thrown in the example stack trace.
On line 20 of the text file, fill in the description of the error being thrown in the example stack trace.