473,569 Members | 2,598 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*******@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

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

Jun 27 '08 #3

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

Similar topics

1
13068
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 statements calling the class objects in my extention DLL. 3. Before each execution I import my extention module using;
3
11544
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 last): File "/usr/local/zope/Zope-2.7.2-0/setup.py", line 1091, in ?
1
11150
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 not callable"
5
20003
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 Here's my script: results = context.module_retriever().tuples() # call to ZSQLMethod converted =
0
1879
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 attempt to load a module at runtime and then request an object of that type. Essentially, my code works as follows: I have a registry class which has...
9
24031
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 I try to run it. I've already posted at ESRI support, and I was hoping that Python people could help me more. I hope there is something simple I...
5
15586
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
8418
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) b = b-1 def perm(n, r):
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 accepts Exception classes. It sounds like you're confusing with some other error, what is the exact message of your 'NoneType error' ? The...
0
7700
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7614
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8125
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7974
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5513
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3642
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2114
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1221
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
938
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.