program structure and control flow exceptions are organized into hierarchy as shown in the table all the exceptions in particular group can be caught by specifying the group name in an except clause here' an exampletrystatements except lookuperrorstatements catch indexerror or keyerror or trystatements except exceptionstatements catch any program-related exception at the top of the exception hierarchythe exceptions are grouped according to whether or not the exceptions are related to program exit for examplethe systemexit and keyboardinterrupt exceptions are not grouped under exception because programs that want to catch all program-related errors usually don' want to also capture program termination by accident defining new exceptions all the built-in exceptions are defined in terms of classes to create new exceptioncreate new class definition that inherits from exceptionsuch as the followingclass networkerror(exception)pass to use your new exceptionuse it with the raise statement as followsraise networkerror("cannot find host "when raising an exceptionthe optional values supplied with the raise statement are used as the arguments to the exception' class constructor most of the timethis is simply string indicating some kind of error message howeveruser-defined exceptions can be written to take one or more exception values as shown in this exampleclass deviceerror(exception)def _init_ (self,errno,msg)self args (errnomsgself errno errno self errmsg msg raises an exception (multiple argumentsraise deviceerror( 'not responding'when you create custom exception class that redefines _init_ ()it is important to assign tuple containing the arguments to _init_ (to the attribute self args as shown this attribute is used when printing exception traceback messages if you leave it undefinedusers won' be able to see any useful information about the exception when an error occurs exceptions can be organized into hierarchy using inheritance for instancethe networkerror exception defined earlier could serve as base class for variety of more specific errors here' an exampleclass hostnameerror(networkerror)pass class timeouterror(networkerror)pass lib fl ff