468,284 Members | 1,601 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,284 developers. It's quick & easy.

Assigning different Exception message

try:
self.cursor.execute(sql)
except AttributeError, e:
if e.message == "oracleDB instance has no attribute 'cursor'":
e.message = 'oracleDB.open() must be called before' + \
' oracleDB.query()'
raise AttributeError, e

This code does not re-assign e's message when the conditional is satisfied.
Why not?

regards
Oct 12 '06 #1
1 1103
Tor Erik Soenvisen wrote:
try:
self.cursor.execute(sql)
except AttributeError, e:
if e.message == "oracleDB instance has no attribute 'cursor'":
e.message = 'oracleDB.open() must be called before' + \
' oracleDB.query()'
raise AttributeError, e

This code does not re-assign e's message when the conditional is
satisfied. Why not?
It does, but e.args is used to generate the message shown:
>>try:
.... None.not_there
.... except AttributeError, e:
.... e.args = ("whatever",)
.... raise e
....
Traceback (most recent call last):
File "<stdin>", line 5, in <module>
AttributeError: whatever

However, I would prefer to rewrite your snippet along the lines:

try:
cursor = self.cursor
except AttributeError:
raise EriksCustomError("oracleDB.open()...")
else:
cursor.execute(sql)

Peter

Oct 12 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by gtz669 | last post: by
10 posts views Thread by Matthew Sims | last post: by
9 posts views Thread by Christopher Weaver | last post: by
10 posts views Thread by Steve Pope | last post: by
8 posts views Thread by =?Utf-8?B?VHJlY2l1cw==?= | last post: by
reply views Thread by NPC403 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.