Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

python assert raise custom exception

This will work. But it's kind of crazy.

try:
    assert False, "A Message"
except AssertionError, e:
    raise Exception( e.args )
Why not the following? This is less crazy.

if not someAssertion: raise Exception( "Some Message" )
It's only a little wordier than the assert statement, but doesn't violate our expectation that assert failures raise AssertionError.

Consider this.

def myAssert( condition, action ):
    if not condition: raise action
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #python #assert #raise #custom #exception
ADD COMMENT
Topic
Name
8+3 =