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 trialJimmy Nguyen
1,940 PointsHow far off am i?
Am I close to the answer or way off?
public class Main {
public static void main(String[] args) {
GoKart kart = new GoKart("yellow");
if (kart.isBatteryEmpty()) {
System.out.println("The battery is empty");
}
try {
kart.drive(2);
}
catch (IllegalArgumentException iae) {
System.out.println("WORK DAM IT!");
System.out.printf("Error was: %s\n", iae.getMessage());
}
}
1 Answer
missgeekbunny
37,033 PointsIt looks like you are pretty close but you never throw the IllegalArgumentException. You need to do that before you can call it.
Mark Miller
45,831 PointsIf it catches an exception, then it has been thrown. You don't manually throw it when using the "try, catch" code block.
Mark Miller
45,831 PointsMark Miller
45,831 PointsYou may be missing a curly brace at the end. I see the opening and closing braces for the 'if' and the 'try' and for the 'catch.' Then, it appears you have only one closing brace for both the class and for the 'main.' Add one closing curly brace at the bottom of the page. Then submit your code.
I passed it with the following code:
try { kart.drive(2); } catch (IllegalArgumentException.illObject) { System.out.println(illObject.getMessage()); }