exception handling is particularly useful when working with user inputor when reading from or writing to filesbecause such interactions are inherently less predictable in section we suggest the syntaxfp opensample txt )for opening file with read access that command may raise an ioerror for variety of reasonssuch as non-existent fileor lack of sufficient privilege for opening file it is significantly easier to attempt the command and catch the resulting error than it is to accurately predict whether the command will succeed we continue by demonstrating few other forms of the try-except syntax exceptions are objects that can be examined when caught to do soan identifier must be established with syntax as followstryfp opensample txt except ioerror as eprintunable to open the fileein this casethe nameedenotes the instance of the exception that was thrownand printing it causes detailed error message to be displayed ( "file not found" try-statement may handle more than one type of exception for exampleconsider the following command from section age int(inputenter your age in years)this command could fail for variety of reasons the call to input will raise an eoferror if the console input fails if the call to input completes successfullythe int constructor raises valueerror if the user has not entered characters representing valid integer if we want to handle two or more types of errors in the same waywe can use single except-statementas in the following exampleage - an initially invalid choice while age < tryage int(inputenter your age in years)if age < printyour age must be positive except (valueerroreoferror)printinvalid response we use the tuple(valueerroreoferror)to designate the types of errors that we wish to catch with the except-clause in this implementationwe catch either errorprint responseand continue with another pass of the enclosing while loop we note that when an error is raised within the try-blockthe remainder of that body is immediately skipped in this exampleif the exception arises within the call to inputor the subsequent call to the int constructorthe assignment to age never occursnor the message about needing positive value because the value of age