I'm making a chess game and I was just wondering if I can get rid of these empty catch blocks in my code and have all the try blocks within the same scope go to a single catch block because I think that this is starting to look a little stupid and unorganized.
My Code:
for (int i = 1; i < 8; i++)
{
try
{
if (board[x + i, y].Equals(blackColor))
checkmateList.AddLast(placementBoard[x + i, y]);//Moving Right
}
catch
{
}
try
{
if (board[x - i, y].Equals(blackColor))
checkmateList.AddLast(placementBoard[x - i, y]);//Moving Left
}
catch
{
}
try
{
if (board[x, y + i].Equals(blackColor))
checkmateList.AddLast(placementBoard[x, y + i]);//Moving Down
}
catch
{
}
}
I have empty catch blocks because the only error I get is an out of bounds exception because it will go off the board so I just stop that search and go in a different area but I think that it just looks stupid because a majority of my code that makes the pieces move consist of this.