I am iterating throu array and sometimes I have to check values that exceed the boundary. Of course it throws exception, but I don’t want to completly stop application after it, just skip this element of code.
Is something like this safe and won’t cause memory leaks?
try
{
if (arrayName[i - 1, j].DoSomething())
something++;
}
catch
{ // empty for purpose
}
It is much better practice to use an if-statement or the like, rather than swallowing exceptions.
You can check a further discussion on the topic here:
Why are empty catch blocks a bad idea?