Quantcast
Viewing latest article 14
Browse Latest Browse All 17

Answer by Jason Baker for Best practice for using assert?

The only thing that's really wrong with this approach is that it's hard to make a very descriptive exception using assert statements. If you're looking for the simpler syntax, remember you can also do something like this:

class XLessThanZeroException(Exception):    passdef CheckX(x):    if x < 0:        raise XLessThanZeroException()def foo(x):    CheckX(x)    #do stuff here

Another problem is that using assert for normal condition-checking is that it makes it difficult to disable the debugging asserts using the -O flag.


Viewing latest article 14
Browse Latest Browse All 17

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>