As I'm sure, you are well aware that python, like most programming languages, comes with built-in exceptions . I went through the list and cannot deduce what would be appropriate. Of course, I can make my own exception, but this is a pretty standard mistake that will be excluded.
This is an instance relationship based error. Class instances are associated with only a few other instances. Calculations can be made depending on different compounds. This error will raise d if you try to calculate in an unrelated instance.
Example
class Foo: def __init__(self,related=None): '''related is a list of Foo instances''' if related is not None: self.related = related else: self.related = [] def compute(self,instance): if instance in self.related:
my thoughts
Honestly, it seems that ValueError will make the most sense because the value is not resolved, but for some reason this does not fully suit me. The fact that there is no relation is the importance of this error, and not just the fact that the value taken is unacceptable.
Is there a better exception than ValueError for my logic?
note: I understand that this ValueError may be the right answer, but I'm curious if there is anything more accurate that I might not be able to see the link when I looked at the documentation.
source share