473,398 Members | 2,812 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,398 software developers and data experts.

Question on try/except

Dan
While perusing sre.py in the standard library, I came upon this snippet
of code in the _compile() function definition:

try:
p = sre_compile.compile(pattern, flags)
except error, v:
raise error, v # invalid expression

Is there some particular use in catching an exception and immediately
re-raising it? Why catch it at all?

/Dan

--
dedded att verizon dott net
Aug 8 '06 #1
2 1172
Dan wrote:
While perusing sre.py in the standard library, I came upon this snippet
of code in the _compile() function definition:

try:
p = sre_compile.compile(pattern, flags)
except error, v:
raise error, v # invalid expression

Is there some particular use in catching an exception and immediately
re-raising it? Why catch it at all?

/Dan
All I can think of is that it changes the traceback to point to the
re-raise and not the original raise.

-Kirk McDonald
Aug 8 '06 #2

Kirk McDonald wrote:
Dan wrote:
Is there some particular use in catching an exception and immediately
re-raising it? Why catch it at all?

All I can think of is that it changes the traceback to point to the
re-raise and not the original raise.
I've used this technique before. It is very useful where (as in the
original re example) recursion might cause a large traceback, and the
error is probably caused by the caller's code. Using this technique
can keep the visible portion of the traceback relevant to the problem
at hand.

Regards,
Pat

Aug 8 '06 #3

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

Similar topics

4
by: Jeff Sykes | last post by:
I have a cgi script that imports modules based on a user config file. I am suffering some performance problems when I import these modules. Some logging revealed that it seems to be taking about...
26
by: djw | last post by:
Hi, Folks- I have a question regarding the "proper" use of try: finally:... Consider some code like this: d = Device.open() try: d.someMethodThatCanRaiseError(...) if SomeCondition: raise...
5
by: Nick Jacobson | last post by:
Say I have a function foo that throws an IndexError exception, and I want to handle it: def foo(a, b, c): print a, b, c #, etc. def main(): #define vars try: foo(a, b, c)
3
by: Ron Adam | last post by:
I'm trying to understand exception handling better and have a question I haven't been able to find an answer too. Which probably means It won't work, but... Do exceptions that take place get...
9
by: Dave H | last post by:
Hello, I have a query regarding definition lists. Is it good practice semantically to use the dt and dd elements to mark up questions and answers in a frequently asked questions list, or FAQ? ...
21
by: Jon Slaughter | last post by:
I have a class that is basicaly duplicated throughout several files with only members names changing according to the class name yet with virtually the exact same coding going on. e.g. class...
6
by: Arthur J. O'Dwyer | last post by:
As far as I know, C89/C90 did not contain the now-standard offsetof() macro. Did C89 mandate that structs had to have a consistent layout? For example, consider the typical layout of the...
42
by: mellyshum123 | last post by:
I need to read in a comma separated file, and for this I was going to use fgets. I was reading about it at http://www.cplusplus.com/ref/ and I noticed that the document said: "Reads characters...
2
by: crybaby | last post by:
Why you specify type and name of the exception in your custom exceptions, but not in built in exceptions except IOError: print "no file by the name ccy_rates*.txt" except MyError, e: print...
10
by: Gerard flanagan | last post by:
Simon Mullis wrote: data = from itertools import groupby datadict = \ dict((k, len(list(g))) for k,g in groupby(data, lambda s: s)) print datadict
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: 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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
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
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,...
0
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...

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.