exceptions == errors?
Mark Harrison
mh at pixar.com
Mon Apr 7 19:47:59 EDT 2003
Are exceptions always considered errors, or there the same feeling
as in C++ that exceptions can be used for non-error situations?
I am asking because I am writing a network server that has the
general outline
while 1:
read request
process request
send response
So, I have the option to
1. embed the "send response" code in the request processing code
2. Have the request processing code generate formatted responses
that are returned to the main loop
As is usually the case, adding robust error checking and reporting
throws a kink into the works. I have to do a lot of exception
wrapping in the request processing code in order to ensure that
there are no code paths where an exception short-circuits a
response generations.
Therefore, I'm thinking of structuring the code like this:
while 1:
try:
read request
process request
catch MyException,e:
send response contained in e
catch Exception,e:
send "internal error" response
Am I setting myself up for trouble if I follow this route?
All advice gratefully received.
--
Mark Harrison
Pixar Animation Studios
More information about the Python-list
mailing list