Like this.
>>> try:
... raise UnrecognizedAirportError("func","arg1","arg2")
... except UnrecognizedAirportError, e:
... print e.args
...
('func', 'arg1', 'arg2')
>>>
Your arguments are in args
, if you simply subclass Exception
.
See http://docs.python.org/library/exceptions.html#module-exceptions
If the exception class is derived from
the standard root class BaseException,
the associated value is present as the
exception instance’s args attribute.
Edit Bigger Example.
class TestSomeException( unittest.TestCase ):
def testRaiseWithArgs( self ):
try:
... Something that raises the exception ...
self.fail( "Didn't raise the exception" )
except UnrecognizedAirportError, e:
self.assertEquals( "func", e.args[0] )
self.assertEquals( "arg1", e.args[1] )
except Exception, e:
self.fail( "Raised the wrong exception" )