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

C#

zeljko mikacic
zeljko mikacic
11,993 Points

still getting OutOfBoundsException

i am still getting OutOfBoundsException i am writing this in visual studio and i have double check every class i wrote and compared it to lessons so far and still getting it. dont know what is wrong

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks;

namespace Igra { class Program { public static void Main() { Map map = new Map(8, 5);

        try
        {
            Path path = new Path(
                new [] {
                    new MapLocation(0,2,map),
                    new MapLocation(1,2,map),
                    new MapLocation(2,2,map),
                    new MapLocation(3,2,map),
                    new MapLocation(4,2,map),
                    new MapLocation(5,2,map),
                    new MapLocation(6,2,map),
                    new MapLocation(7,2,map)
                }
            );

            MapLocation location = path.GetLocationAt(1);
            Console.WriteLine(location.X + "," + location.Y);
        }
        catch (OutOfBoundsException ex)
        {
            Console.WriteLine(ex.Message);
        }
        catch (TreeeHouseDefenseException)
        {
            Console.WriteLine("Unhandled Treehouse Defense exception");
        }
        catch (Exception)
        {
            Console.WriteLine("Unhandled exception");
        }

    }
}

}

1 Answer

Steven Parker
Steven Parker
231,269 Points

:point_right: The error could be elsewhere in the code.

My first inclination would be to look for an error in Map.OnMap or in the constructor for MapLocation.