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 trial

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)