473,396 Members | 1,892 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Cathing several potential errors?

cnb
if i do
try:
something
except TypeError, IndexError:
pass

only the first error will get caught. I dont want to use Exception and
catch all errors, but just 2. how can i do that?
Sep 6 '08 #1
3 805
On Sat, 6 Sep 2008 15:13:45 -0700 (PDT), cnb wrote:
if i do
try:
something
except TypeError, IndexError:
pass
Parenthesize them:

except (TypeError, IndexError):

--
Regards,
Wojtek Walczak,
http://tosh.pl/gminick/
Sep 6 '08 #2
On Sep 7, 8:13*am, cnb <circularf...@yahoo.sewrote:
if i do
try:
* * something
except TypeError, IndexError:
* * pass

only the first error will get caught. I dont want to use Exception and
catch all errors, but just 2. how can i do that?
The syntax for what you can have between "except" and ":" is:
[expression ["," target]]
'target' is an optional name to be bound to the actual exception
object that is raised.
If you want to catch multiple kinds of exception, 'expression' needs
to be a tuple.

See
http://docs.python.org/tut/node10.ht...00000000000000
and
http://docs.python.org/ref/try.html

Cheers,
John
Sep 6 '08 #3
cnb wrote:
if i do
try:
something
except TypeError, IndexError:
pass

only the first error will get caught. I dont want to use Exception and
catch all errors, but just 2. how can i do that?
--
http://mail.python.org/mailman/listinfo/python-list
what you're doing is assigning the value of TypeError to the name IndexError

try:
somthing
except (TypeError, IndexError):
pass

use

except (TypeError, IndexError), e:
print e

if you want to print the error
Sep 6 '08 #4

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

Similar topics

10
by: B Moor | last post by:
Host PC: Win SBS 2003 with 2.6 GHz processor and 1GB RAM SQL Server 2000 sp3 (or latest).MS Office 2k3 I have the access 2k3 front end running on server (this may get changed) and all was well...
14
by: nd02tsk | last post by:
Hello Why is it that PostgreSQL chooses to have features like replication, fulltext indexing and GIS maintained by others outside of the sourcetree? I appreciate any answers. Thank you. ...
8
by: vidya.bhagwath | last post by:
Hello Experts, I am using std::string object as a member variable in one of the my class. The same class member function operates on the std::string object and it appends some string to that...
0
by: svgeorge | last post by:
I want to update several tables using one stored procedure. How can i do this I mean the syntax.etc. declaration etc. I know the basic syntax as below CREATE PROCEDURE <Procedure_Name, sysname,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.