if an ioerror occursdetails concerning the cause of the error are placed in and control passes to the code in the except block if some other kind of exception is raisedit' passed to the enclosing code block (if anyif no errors occurthe code in the except block is ignored when an exception is handledprogram execution resumes with the statement that immediately follows the last except block the program does not return to the location where the exception occurred the raise statement is used to signal an exception when raising an exceptionyou can use one of the built-in exceptionslike thisraise runtimeerror("computer says no"or you can create your own exceptionsas described in the section "defining new exceptionsin program structure and control flow proper management of system resources such as locksfilesand network connections is often tricky problem when combined with exception handling to simplify such programmingyou can use the with statement with certain kinds of objects here is an example of writing code that uses mutex lockimport threading message_lock threading lock(with message_lockmessages add(newmessagein this examplethe message_lock object is automatically acquired when the with statement executes when execution leaves the context of the with blockthe lock is automatically released this management takes place regardless of what happens inside the with block for exampleif an exception occursthe lock is released when control leaves the context of the block the with statement is normally only compatible with objects related to system resources or the execution environment such as filesconnectionsand locks howeveruser-defined objects can define their own custom processing this is covered in more detail in the "context management protocolsection of "types and objects modules as your programs grow in sizeyou will want to break them into multiple files for easier maintenance to do thispython allows you to put definitions in file and use them as module that can be imported into other programs and scripts to create moduleput the relevant statements and definitions into file that has the same name as the module (note that the file must have py suffix here' an examplefile div py def divide( , ) / * return ( ,rif and are integersq is an integer to use your module in other programsyou can use the import statementimport div ab div divide( lib fl ff