Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialRachelle Wood
15,362 PointsCode worked in workspaces but not in challenge
I have checked, rechecked and rechecked, but I can't get this code to work in the challenge. It works great in workspaces though. What am I doing wrong?
public class Main {
public static void main(String[] args) {
GoKart kart = new GoKart("yellow");
if (kart.isBatteryEmpty()) {
System.out.println("The battery is empty");
}
kart.drive(2);
try {
kart.drive(100);
} catch (IllegalArgumentException ex) {
System.out.printf("Error message: %s\n", ex.getMessage());
}
}
}
1 Answer
Cory Madden
7,120 PointsGet rid of the line right before your try statement. The one that says kart.drive(2)
It's not catching the exception on that call to the method.
Rachelle Wood
15,362 PointsHi Corey. Thanks so much!! I thought that since kart.drive(2) was outside of the try catch block that it would not be in conflict with it. Live and learn as they say :)
Rachelle Wood
15,362 PointsRachelle Wood
15,362 PointsI get an error message saying that IllegalArgumentException was not caught.