471,091 Members | 1,553 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

Re: Error Handling

En Thu, 17 Apr 2008 16:19:12 -0300, Victor Subervi <vi***********@gmail.comescribió:
print '¡Exito en introducir!<br />'
print '<i>Esta página va a regresar a la página principal del carrito
de compras en 10 segundos.</i>'
except IntegrityError:
print 'Lo siento, pero el ID que entraste está usado actualmente por
otra entrada. Favor de dar para atráz y escojer otro número.'
except OperationalError:
print 'Lo siento, pero has añadido un carácter extraño a un número (o
en "ID", "precio", "recámaras" o "baños". Favor de dar para atráz y escojer
otro número.'
print 'Lo siento, pero hay un error. Favor de dar para atráz y
averiguar donde está el error, y reintentar.'
When I enter and ID that is not a number, it should trigger the
IntegrityError. Instead, I get this in the error log:

[Thu Apr 17 12:06:37 2008] [error] [client] PythonHandler
mod_python.cgihandler: NameError: global name 'IntegrityError' is not
defined, referer: http://livestocksling.com/bre/iud.py
Looks like IntegrityError and OperationalError are defined inside your database module. Either use:

from my_database_module import IntegrityError, OperationalError

except OperationalError: ...
except IntegrityError: ...
except Exception: ...

or else:

import my_database_module

except my_database_module.OperationalError: ...
except my_database_module.IntegrityError: ...
except Exception: ...

It's the same as any other symbol, like math.sqrt or os.rename

Note that I've not used a bare except: clause; it's not a good idea. sys.exit() raises the SystemExit exception, and pressing Ctrl-C raises KeyboardInterrupt; a bare except: will catch them, effectively nullifying the intended purpose.

Gabriel Genellina

Jun 27 '08 #1
0 641

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

12 posts views Thread by Christian Christmann | last post: by
13 posts views Thread by Thelma Lubkin | last post: by
3 posts views Thread by Stefan Johansson | last post: by

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.