Creating a custom warning for my library. Subclass Warning or UserWarning?

Viewed 19

I am writing a library and I want to warn users about some potentially-hazardous situations that are not "bad enough" to warrant crashing their program with an exception.

I am planning to implement my own warning class for this purpose. Should I subclass Warning, or UserWarning?

The docs aren't really clear on this point. It seems like I should subclass Warning, and leave UserWarning for the "default" case of a user just typing warnings.warn(), but I'm not sure if there is a particular convention, rule, or generally-accepted practice on this subject.

0 Answers
Related