Recommendations (or best practices) to define functions (or methods)
"Martin v. Löwis"
martin at v.loewis.de
Mon Jan 8 09:36:02 CET 2007
Frank Millman schrieb:
> If there is something wrong with the SQL statement, I do not want to
> crash the server, I want to notify the client that there was something
> wrong, so that the offending module can be corrected and reloaded.
Right. In a distributed system, you should propagate the error (in some
form) to the client.
Then the question is what the best form is: IMO, you should keep as
much information as possible. This means you either return the Python
exception to the client, to be re-raised on the client side, or you
log the exception on the server side, and just return to the client
the information that the full error message has been logged.
In any case: this should happen on the middleware layer, i.e. the place
that does the communication. Wrt. the OP's code, I still maintain that
all of his approaches to "silence" the exception are flawed. Exception
handling should either recover from the error (e.g. by adjusting the
environment, then retrying) or abort the execution. In a distributed
case, "abort the execution" may not mean "terminate the program", but
instead "immediately abort execution of the current request and return
an error to the client".
More information about the Python-list