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 trialRobert Roberson
Courses Plus Student 8,401 PointsOk, once again I have understood nothing.
I don't even know what to ask. Here is the code. This is what I saw in the video but it does not work.
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(3);
System.out.println("You're running out of gas!");
} catch { (IllegalArguementException);
}
}
2 Answers
tobiaskrause
9,160 Pointspublic 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 e) {
System.out.println(e.getMessage());
}
}
}
I would suggest you to watch the videos agian :) Feel free to ask something.
I also would suggest you to write the basic syntax in a text file so you will remember it. Or google it. A simple google search of "java try catch" and "java exception message" would have give you to the answer
John Marley
8,740 PointsAlso, there is a typo in argument in IllegalArgumentException. This might be it too but I don't know too much about it.