[Python] Proper exception to raise if None encountered as argument

Discussão em 'Python' iniciado por Stack, Junho 18, 2025.

  1. Stack

    Stack Membro Participativo

    What is the "proper" exception class to raise when one of my functions detects None passed where an argument value is required? For instance:

    def MyFunction(MyArg1, MyArg2):

    if not MyArg2:
    raise ?Error?


    I think I've seen TypeError used here (and it's true that I'm receiving a NoneType where some other type is expected) but that doesn't strike me as quite right for this situation where I think the Exception could be more explicit.

    Continue reading...

Compartilhe esta Página