I have a database connection object, and I want to restrict/enforce max number of calls to it's write operation (function). I have mocked it in tests, and have overridden the write method to monitor calls to it.
However, I am confused about what error to raise when it's called more than the max number allowed (say 2). I've gone through the docs but haven't found anything suitable. (Hence, as it suggests) I have used RuntimeError
but I am not fully convinced about the message it gives (not the explicit message I display, but the implicit meaning conveyed by the class itself). I feel AttributeError
to be a far fit, but nothing else come that close to correctness.
Is there any other builtin exception class which is more suitable for this?