passing extra state information along in the exception itself allows the try statement to access it more reliably with classesthis is nearly automatic as we've seenwhen an exception is raisedpython passes the class instance object along with the exception code in try statements can access the raised instance by listing an extra variable after the as keyword in an except handler this provides natural hook for supplying data and behavior to the handler for examplea program that parses data files might signal formatting error by raising an exception instance that is filled out with extra details about the errorclass formaterror(exception)def __init__(selflinefile)self line line self file file def parser()raise formaterror( file='spam txt'when error found tryparser(except formaterror as xprint('error at% % ( filex line)error atspam txt in the except clause herethe variable is assigned reference to the instance that was generated when the exception was raised this gives access to the attributes attached to the instance by the custom constructor although we could rely on the default state retention of built-in superclassesit' less relevant to our application (and doesn' support the keyword arguments used in the prior example)class formaterror(exception)pass inherited constructor def parser()raise formaterror( 'spam txt'no keywords allowedtryparser(except formaterror as xprint('error at:' args[ ] args[ ]error at spam txt not specific to this app providing exception methods besides enabling application-specific state informationcustom constructors also better support extra behavior for exception objects that isthe exception class can also define methods to be called in the handler the following code in excparse pyfor exampleadds method that uses exception state information to log errors to file automaticallycustom data and behavior