AI engineering glossary · Python core
What is try/except?
try/except (also called exception handling): A construct that runs a block of code and, if it raises an exception, jumps to a matching except block to handle it instead of crashing. You can name the exception types to catch and add an else block for the no-error case.
try/except: an example
try: n = int(text) except ValueError: n = 0 sets n to 0 when text is 'abc'.
Related terms
More Python core terms
Where you learn it
try/except is part of the AI Engineering Program, which teaches it with notes, a hands-on lab and an exam. The first lesson is free.