What are the implications of using assert vs. raise exception

Are there any significant differences in the following:

raise Exception("some exception") assert False, "some exception" 
+6
source share
1 answer

Assertions can be disabled with the -O value when running Python. For this reason, use statements only to verify that it is working, and not to verify that it is part of your program logic.

Also, of course, there is a difference in the fact that statements raise an AssertionError that you really shouldn't catch. When you throw an exception, you can make the type of exception suitable for the error and catch it later.

+19
source

Source: https://habr.com/ru/post/958408/


All Articles