catching an exception there are several philosophies regarding how to cope with possible exceptional cases when writing code for exampleif division / is to be computedthere is clear risk that zerodivisionerror will be raised when variable has value in an ideal situationthe logic of the program may dictate that has nonzero valuethereby removing the concern for error howeverfor more complex codeor in case where the value of depends on some external input to the programthere remains some possibility of an error one philosophy for managing exceptional cases is to "look before you leap the goal is to entirely avoid the possibility of an exception being raised through the use of proactive conditional test revisiting our division examplewe might avoid the offending situation by writingif ! ratio elsedo something else second philosophyoften embraced by python programmersis that "it is easier to ask for forgiveness than it is to get permission this quote is attributed to grace hopperan early pioneer in computer science the sentiment is that we need not spend extra execution time safeguarding against every possible exceptional caseas long as there is mechanism for coping with problem after it arises in pythonthis philosophy is implemented using try-except control structure revising our first examplethe division operation can be guarded as followstryratio except zerodivisionerrordo something else in this structurethe "tryblock is the primary code to be executed although it is single command in this exampleit can more generally be larger block of indented code following the try-block are one or more "exceptcaseseach with an identified error type and an indented block of code that should be executed if the designated error is raised within the try-block the relative advantage of using try-except structure is that the non-exceptional case runs efficientlywithout extraneous checks for the exceptional condition howeverhandling the exceptional case requires slightly more time when using tryexcept structure than with standard conditional statement for this reasonthe try-except clause is best used when there is reason to believe that the exceptional case is relatively unlikelyor when it is prohibitively expensive to proactively evaluate condition to avoid the exception