Ben Chuanlong Du's Blog

It is never too late to learn.

Exception and Error Handling in Python

Tips and Traps

  1. If you need trackback information when throwing an exception use raise ExceptionClass(msg), otherwise, use sys.exit(msg) instead.

  2. The assert statement (which raises AssertionError if the assertion is not met) is a very good way to ensure conditions to be met.

     :::python
     assert some_condition