Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Java Java Objects (Retired) Harnessing the Power of Objects Handling Exceptions

Rodrigo Gomez-Palacio
Rodrigo Gomez-Palacio
1,125 Points

Code is not accepting my answer

The error message I am getting is "Please print out the message using the System.out object."

I thought I did use the system.out object!

public class Main {
    public static void main(String[] args) {
        GoKart kart = new GoKart("yellow");
        if (kart.isBatteryEmpty()) {
          System.out.println("The battery is empty");
      catch(IllegalArgumentException iae){
        System.out.println("Not enough battery");


2 Answers

Your code is set up the correct way, but you aren't getting the error message from IllegalArgumentException.

System.out.printf("Experiencing an error: %s", iae.getMessage());
try {
      } catch (IllegalArgumentException iae) {
        System.out.println("Whoa there!");
        System.out.printf("The error was: %s%n", iae.getMessage());

Above, is the code example to follow. Instead of dispenser.load(400), you are trying kart.drive(2)