Design question regarding exceptions.
James Stroud
jstroud at mbi.ucla.edu
Tue Jul 17 17:19:18 EDT 2007
asincero wrote:
> I have a class called Users that provides a higher level of
> abstraction to an underlying "users" table in a pgsql database. It
> has methods like "addUser()" and "deleteUser()" which, obviously, wrap
> the corresponding SQL statements. My question is would it better to
> let any exceptions thrown by the underlying DB-API calls bubble up
> from these methods, or should I catch them inside the methods, wrap
> them inside my own custom exceptions, and throw those exceptions
> instead?
>
> Thanks.
>
> -- Arcadio
>
I don't think its wise to mask or otherwise waste cpu cycles catching
and re-throwing lower level exceptions. If you anticipate problems with
certain inputs, test for those possibilities and raise custom exceptions
at module level. At package level, you can import a module with your
package exceptions defined.
James
--
James Stroud
UCLA-DOE Institute for Genomics and Proteomics
Box 951570
Los Angeles, CA 90095
http://www.jamesstroud.com/
More information about the Python-list
mailing list