Instead of asking if something needs to return a value or throw an exception, you need to ask what function it promises to do. If the function promises to move a node, it should throw an exception if it cannot. If the promises function moves a node, if possible, or indicates through the return value that it cannot be moved, but only throws an exception, if the data structure is fundamentally corrupt in some way than is implied in the ability to move the node, it should do it . Sometimes it is useful to provide functions like βdo itβ and βtryβ.
Regarding the type of exception for the throw, I frankly do not like the concept of throwing most of the built-in types of exceptions from the user code, since there is no good programmatic way to determine if there was an ArgumentException exception from your routine or from some ordinary one that was called by your procedure, and most exceptions say nothing about the quality of the underlying data structure.
If you try, for example, to parse a file from disk and integrate it with an existing data structure and throw an exception, it does not matter if there was an ArgumentException or a SubscriptOutOfBoundsException or a DiskReadErrorException or something else. Most importantly, whether the parsing attempt was discarded in such a way as to leave the data structure reliable; Of secondary importance is whether it will be possible to parse the file differently or under other circumstances. The type of exception really matters only to the extent that it can answer these first two questions.
source share