Design recommendation wanted.
Istvan Albert
ialbert at mailblocks.com
Thu Sep 23 23:31:32 EDT 2004
Yannick Turgeon wrote:
> With this solution, I will get lost very soon. I feel that I would need a
> kind of State-Managing system/class that would keep track of the command
It would simplify your life if you dealt with
the problems (that can be dealt with) on the spot, as they
happen. Don't use the exceptions as a mechnism to jump out of a
block of code. This is so much easier to follow:
if packet_type == ERROR1:
...deal with it..
elif packet_type == ERROR2:
...deal with it ...
else:
try:
c = PACKETS[packet_type](data)
except ...:
...deal with this
You don't have to have to put your code in one try/except
block. This only depens on the nature of the response that
you want to invoke when an exeption occurs. Feel free to nest them
as needed. Keep the error and the response to it as one logical
entity as much as possible.
Istvan.
More information about the Python-list
mailing list