Re: NoneType Error

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Gabriel Genellina

    Re: NoneType Error

    En Sun, 15 Jun 2008 05:35:18 -0300, Maryam Saeedi <ma.saeedi@gmai l.comescribió:
    I am using a python program on a lot of different documents and for few of
    them I will get NoneType error. I just want to skip those files and continue
    for others, I do this without a problem for
    IndexError,Type Error,ValueErro r,NameError :
    >
    try:
    ....
    except (IndexError,Typ eError,ValueErr or,NameError):
    ....
    >
    but when I add NoneType it gives the following error:
    except (NoneType,Index Error,TypeError ,ValueError,Nam eError):
    NameError: name 'NoneType' is not defined
    >
    and if I do not use the NoneType then it does not go through either and
    stops the program when I get to such a file. Is there another name that
    captures this error?
    NoneType is not an exception, but the type of the None object. Perhaps you're not interpreting correctly some error messages:
    >>x=None
    >>x()
    Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
    TypeError: 'NoneType' object is not callable

    (the exception raised is a TypeError; NoneType is part of the message).

    It appears that you want to catch all exceptions, just use Exception for that:
    try:
    ...
    except Exception:
    ...

    --
    Gabriel Genellina

  • Bruno Desthuilliers

    #2
    Re: NoneType Error

    Gabriel Genellina a écrit :
    En Sun, 15 Jun 2008 05:35:18 -0300, Maryam Saeedi <ma.saeedi@gmai l.comescribió:
    (snip)
    It appears that you want to catch all exceptions, just use Exception for that:
    try:
    ...
    except Exception:
    ...
    >
    Hem... That's definitively *not* an a good advice here IMHO. A catch-all
    may be useful near a program's 'top-level' to handle any other unhandled
    exception in a more user-friendly way (ie : log the error, warns whoever
    is in charge, try to cleanly dispose of resources / data / whatever so
    we don't break anything, and display a nice and visible error message to
    the user), but anywhere else you really want to know *exactly* which
    exception(s) you're expecting to handle here and let the other propagate.

    Comment

    • Gabriel Genellina

      #3
      Re: NoneType Error

      En Mon, 16 Jun 2008 06:29:09 -0300, Bruno Desthuilliers <bruno.42.desth uilliers@websit eburo.invalides cribió:
      Gabriel Genellina a écrit :
      >
      >It appears that you want to catch all exceptions, just use Exception for that:
      >try:
      > ...
      >except Exception:
      > ...
      >
      Hem... That's definitively *not* an a good advice here IMHO. A catch-all
      may be useful near a program's 'top-level' to handle any other unhandled
      exception in a more user-friendly way (ie : log the error, warns whoever
      is in charge, try to cleanly dispose of resources / data / whatever so
      we don't break anything, and display a nice and visible error message to
      the user), but anywhere else you really want to know *exactly* which
      exception(s) you're expecting to handle here and let the other propagate.
      Yes, thanks for putting it perfectly clear - more clear than I could have written.

      --
      Gabriel Genellina

      Comment

      Working...