except exception as xprint(xsaveit division by zero nameerrorname 'xis not defined saveit zerodivisionerror('division by zero',python removes this reference assign exc to retain exc if needed propagating exceptions with raise the raise statement is bit more feature-rich than we've seen thus far for examplea raise that does not include an exception name or extra data value simply reraises the current exception this form is typically used if you need to catch and handle an exception but don' want the exception to die in your codetryraise indexerror('spam'except indexerrorprint('propagating'raise propagating traceback (most recent call last)file ""line in indexerrorspam exceptions remember arguments reraise most recent exception running raise this way reraises the exception and propagates it to higher handler (or the default handler at the topwhich stops the program with standard error messagenotice how the argument we passed to the exception class shows up in the error messagesyou'll learn why this happens in the next python exception chainingraise from exceptions can sometimes be triggered in response to other exceptions--both deliberately and by new program errors to support full disclosure in such casespython (but not xalso allows raise statements to have an optional from clauseraise newexception from otherexception when the from is used in an explicit raise requestthe expression following from specifies another exception class or instance to attach to the __cause__ attribute of the new exception being raised if the raised exception is not caughtpython prints both exceptions as part of the standard error messagetry except exception as eraise typeerror('bad'from exception coding details explicitly chained exceptions