In this lecture, a try/catch is executed because we know that we’ll be referencing a dictionary item that might not exist.
It’s also possible to check if the object exists with a statement like this one:
if (grid.ContainsKey(explorationCoordinates))
This would check safety before executing and simply not complete if the position does not exist. However, if there are other reasons why the dictionary positions might not be accessible, we’ll get an error that isn’t “caught”.
I’ve used basic checks like the if command above forever, but it doesn’t feel quite as safe. Does anyone have a feeling on the best way to handle these situations?