У меня есть схема управления, с которой я общаюсь через последовательный порт. Если команда ответа не соответствует определенному формату, я считаю это ошибкой, и мне было интересно, должен ли я вернуть код ошибки или выдать исключение? Например:
public double GetSensorValue(int sensorNumber)
{
...
string circuitCommand = "GSV,01," + sensorNumber.ToString(); // Get measurement command for specified sensor.
string responseCommand;
string expectedResponseCommand = "GSV,01,1,OK";
string errorResponseCommand = "ER,GSV,01,1,62";
responseCommand = SendReceive(circuitCommand); // Send command to circuit and get response.
if(responseCommand != expectedResponseCommand) // Some type of error...
{
if(responseCommand == errorResponseCommand) // The circuit reported an error...
{
... // How should I handle this? Return an error code (e.g. -99999) or thrown an exception?
}
else // Some unknown error occurred...
{
... // Same question as above "if".
}
}
else // Everything is OK, proceed as normal.
...
}
Спасибо!