Catching Exception

To distinct the certain exception with other general exceptions, we could use hierarchical catching exception method.

try
{
    MapLocation mapLoc = new MapLocation(8, 5, map);
}
catch (OutOfBoundsException ex)
{
    Console.WriteLine(ex.Message);
}
catch (MakersDefenseException)
{
    Console.WriteLine("Unhandled MakersDefenseException");
}
catch (Exception ex)
{
    Console.WriteLine("Unhandled Exception");
}

results matching ""

    No results matching ""