473,503 Members | 2,150 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Re: NoneType Error

En Sun, 15 Jun 2008 05:35:18 -0300, Maryam Saeedi <ma*******@gmail.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,TypeError,ValueError,NameError :

try:
....
except (IndexError,TypeError,ValueError,NameError):
....

but when I add NoneType it gives the following error:
except (NoneType,IndexError,TypeError,ValueError,NameErro r):
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

Jun 27 '08 #1
2 7434
Gabriel Genellina a écrit :
En Sun, 15 Jun 2008 05:35:18 -0300, Maryam Saeedi <ma*******@gmail.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.
Jun 27 '08 #2
En Mon, 16 Jun 2008 06:29:09 -0300, Bruno Desthuilliers <br********************@websiteburo.invalidescribi ó:
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

Jun 27 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
13048
by: Atul Kshirsagar | last post by:
Hello, I am using Python 2.3.2 with a C++ extention DLL in muti-threaded environment. 1. For each new thread I create a separate sub-interpreter. 2. Each thread executes multiple python...
3
11533
by: Martin Koekenberg | last post by:
Hello, Ik get the following error when I install a new Python software package such as Zope or PIL. This is what I get whem I 'make' Zope : running build_ext Traceback (most recent call...
1
11147
by: homepricemaps | last post by:
if i do the following i get the url of an image i am looking for image = "" image = bs.img print image however if i do this out.write (image ) i get an error that says "nonetype error is...
5
19986
by: Jon Bowlas | last post by:
Hi listers, I wrote this script in Zope some time ago and it worked for a while, but now I'm getting the following error: TypeError: coercing to Unicode: need string or buffer, NoneType found ...
0
1875
by: John Allman | last post by:
Hi all, I'm trying to create a setup which allows a program to request an object using strings and get an object of that type. It appears to be mostly working but i have difficulties if i...
9
24019
by: thompson.marisa | last post by:
Hi. I'm extremely new to Python and programming as a whole. I have written a python script with the assistance of ESRI ArcGIS 9.2, which uses Python 2.4.1, however, it gives me this error when...
5
15584
by: tom | last post by:
Hi! My code is And it gives following error: How can sortedList variable turn into NoneType? I just don't get it...
2
8412
by: Jordan Harry | last post by:
I'm trying to write a simple program to calculate permutations. I created a file called "mod.py" and put the following in it: def factorial(n): a = n b = n while a>0 and b>1: n = (n)*(b-1)...
0
240
by: =?utf-8?q?C=C3=A9dric_Lucantis?= | last post by:
Hi, Le Sunday 15 June 2008 10:35:18 Maryam Saeedi, vous avez écrit : you can get the none type with None.__class__ or with the 'types' module, but it won't work as the except handler only...
0
7205
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7093
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7349
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7008
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7467
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
4688
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3168
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
746
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
399
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.