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# C# Objects Inheritance Throwing Exceptions

Why do I get this error?[SOLVED]

I get the following error when I run this code, can someone please tell me what is wrong?

Game.cs(13,37): error CS1729: The type TreehouseDefense.MapLoc ation' does not contain a constructor that takes3' arguments
MapLocation.cs(5,12): (Location of the symbol related to previo
us error)
MapLocation.cs(7,12): error CS0103: The name `map' does not exi
st in the current context

Here is my code for Game.cs using System;

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

      try
      {
      MapLocation mapLocation = new MapLocation(20, 20, map);
      }
      catch(Exception)
      {
        Console.WriteLine("That map location is not on the map!");
      }




    }
}

}

and here is code for MapLocation.CS

namespace TreehouseDefense { class MapLocation : Point { public MapLocation(int x, int y) : base(x, y) { if (!map.OnMap(this)) { throw new System.Exception(); } } }

}

its ok, I've worked it out. I hadn't passed a 3rd parameter to the MapLocation constructor

1 Answer

Steven Parker
Steven Parker
231,271 Points

Congrats on figuring it out for yourself. :+1:

You could put [SOLVED] at the front of the title as an alternative to chosing a "best answer".