Are there any significant differences with the following?
raise Exception(\"some exception\")
assert False, \"some exception\"
Assertions can be disabled with the -O
flag when starting Python. For this reason, use assertions only for sanity-checking, not for checking that is part of your program logic.
Besides this, there is of course the difference that assertions raise AssertionError
, which you really shouldn't catch. When you raise an exception, you can make the type of the exception appropriate to the error and catch it later.