Modify Exception
Exception is used to communicate about the error. In other words, exceptions are the communication from programmer to users about how to resolve the issues. Exception mostly happened from programming mistakes.
Let's change our code to be more understandable.
if (!map.onMap(this))
{
throw new Exception(x +","+y+" outside the range");
}
try
{
MapLocation mapLoc = new MapLocation(8, 5, map);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}