BACnet
BACnet copied to clipboard
Return empty byte array if no data is present
If no data is e.g. stored in a trendlog, an empty byte array should be returned instead of throwing an exception. Due to the fact that we query data from a certain point in time on, it is quite a valid state that a trendlog has no data recorded. Exceptions should not be used to control the program flow, it makes more sense to return empty data.
Please note: second commit represents the undo of the solution file changes.
+1
Hi @patrickthoma, I agree that the way it works now is not great. However, exceptions can be used to control program flow imho, as long as they are used only in situations that really need it (like errors that can cause short circuiting). But in this case, if no data is available, indeed I would expect an empty array rather than exception.
Regarding your proposed solution, I see one problem. The original author has implemented the method this way, that the returned item count value of 0 has a special meaning (not something .NET developer would expect, but I think something that is more common in low level programming). When 0 is returned, it can either mean there was no data returned (and that is what you are referring to in your proposed change, this should not throw an exception) or it can mean there was an error processing the response (in this case exception would be valid). So you would like to address both situations. Right now you will be hiding all response processing errors and returning empty arrays.