Question about raise and exceptions.

Steven W. Orr steveo at syslang.net
Wed Feb 28 16:49:08 EST 2007


On Wednesday, Feb 28th 2007 at 22:03 +0100, quoth Bruno Desthuilliers:

=>Daniel Klein a ?crit :
=>> On Wed, 28 Feb 2007 13:48:54 -0500 (EST), "Steven W. Orr"
=>> <steveo at syslang.net> wrote:
=>> 
=>> 
=>>>When I run it I get this:
=>>>
=>>>884 > ./t_fsm.py
=>>>Traceback (most recent call last):
=>>>  File "./t_fsm.py", line 3, in ?
=>>>    from fsm import *
=>>>  File "/home/boston/VIASAT/sorr/py/fsm/fsm.py", line 76
=>>>    raise TransitionError, self.curr_state, newstate, "Going to error 
=>>>state %d from state %d" % (self.curr_state, newstate)
=>>>                                                    ^
=>>>SyntaxError: invalid syntax
=>> 
=>> 
=>> The arguments for TransitionError must be a tuple, 
=>
=>Err...
=>
=>> eg:
=>> 
=>> msg = "Going to error state %d from state %d" % (self.curr_state,
=>> newstate)
=>> raise TransitionError(self, curr_state, newstate, msg)
=>
=>Where did you see a tuple here ? You're code is *calling* 
=>TransitionError, passing it the needed arguments.
=>
=>Note that it's the correct syntax - but not the correct explanation !-)

Ok. Now I'm potentially confused:
1. TransitionError takes 4 args
2. raise takes a tuple with four elements after the exception argument as 
its 2nd arg

I take it you mean #2?

-- 
Time flies like the wind. Fruit flies like a banana. Stranger things have  .0.
happened but none stranger than this. Does your driver's license say Organ ..0
Donor?Black holes are where God divided by zero. Listen to me! We are all- 000
individuals! What if this weren't a hypothetical question?
steveo at syslang.net



More information about the Python-list mailing list