Kotlin
Java

MP Debugging Part 1
Java

Created By: Geoffrey Challen
/ Updated: 2022-11-10

Welcome back! This short lesson is our second on debugging strategies that will both help you with your project, and in your future as a software creator.

This lesson completes the checklist that we'll expect you to have followed before you receive help on the help site. But we also expect that, by following these steps, you'll find your mistakes faster, with less frustration, and needing less help from us. So let's get to it!

Steps 0, 1, and 2

If you haven't already, check out the previous lesson on debugging for the first three steps in our checklist. To review, they are:

  1. Tidy up your code, so that you and we can read it
  2. Identify the problem by examining the test cases and being able to explain how your code is behaving differently than expected
  3. Add log messages to help test hypotheses and understand how your code is actually behaving

Step 3: Reading Exception Stack Traces

When you encounter an error in your program, frequently a piece of debugging output called a stack trace is generated. Here's an example drawn from the video walkthrough below:

Initially, this looks like a pretty intimidating mound of text! But, buried within are some incredibly useful nuggets of information. And by familiarizing yourself with stack traces and their contents, you can frequently at least figure out what is going wrong, and sometimes the solution as well. Let's explore how to read exception stack traces, and use them to understand what is going wrong with our code.

Step 4: Searching for Help

Next comes the part where the old geezer faculty member is going to tell you how to use the internets. Search? I can tell what you're thinking. Really? You're going to show me how to search the internet? I know how to do that!

I don't doubt it. But, nonetheless, I have a few tips that you might find useful.

Bonus Step: Using Git to Identify and Undo Changes

We consciously covering too many details about Git in this course. You'll learn more about it in later courses, and on some level Git can't really be properly understood outside of a collaborative multi-person project.

But, it's worth knowing how to do a few simple things. Let's discuss two Git fundamentals—determining what you've changed, and undoing those changes when you've made a mistake.

Summary

That's all for this lesson! To recap, going forward, here are the steps that we'll expect you have to completed before you ask for help using the help site or forum:

  1. Tidy up your code, so that you and we can read it
  2. Identify the problem by examining the test cases and being able to explain how your code is behaving differently than expected
  3. Add log messages to help test hypotheses and understand how your code is actually behaving
  4. Understand any relevant exception stack traces to gain a clearer picture of what is going wrong
  5. Have searched the forum and Google as appropriate to find out more information about what went wrong

More Practice

Need more practice? Head over to the practice page.