I have this code block:
try
{
int QuestionAnswerID = 0;
// code block which assign value to QuestionAnswerID
item.QuestionAnswerID = QuestionAnswerID;
}
catch (NullReferenceException)
{
item.QuestionAnswerID = -999;
}
This runs in a loop and this surely run into catch block 2-3 times within the loop. This code does exactly what I wanted but just wanted to know whether it is a bad practice to handle a known problem using try-catch block.
Will it be more efficient if I use if statement/s to identify null value before throwing excenption?