I have a variable which I know will be invalid if it is zero, so would like to catch this situation. I started coding this as an ArgumentOutOfRangeException
but when I do this I get a blue squiggly line appearing under the first parameter for this exception type (paramName); as the variable I am referencing is not an argument of the procedure.
The value is being set from a call to a separate assembly (possibly not written by 'us', so am looking to handle the exception locally)
I've spent a while Googling, and looking at the options in intellisense, but can't see predefined exception that fits. Any suggestions for a better option than leaving as is or using the generic Exception
?
Example of what I am doing for clarity:
public long MyProcedure(long incomingVariable)
{
long eventId = ThirdParty.GetEventId(incomingVariable);
if (eventId == 0)
{
eventId = ThirdParty.SecondaryCall();
}
if (eventId == 0)
{
throw new ArgumentOutOfRangeException("eventId", "Event ID of zero");
}
}