Design recommendation wanted.
ialbert at mailblocks.com
Fri Sep 24 05:31:32 CEST 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 ...
c = PACKETS[packet_type](data)
...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.
More information about the Python-list