raise class raise raise instance of class make and raise instance of classmakes an instance reraise the most recent exception as mentioned earlierexceptions are always instances of classes in python and later hencethe first raise form here is the most common--we provide an instance directlyeither created before the raise or within the raise statement itself if we pass class insteadpython calls the class with no constructor argumentsto create an instance to be raisedthis form is equivalent to adding parentheses after the class reference the last form reraises the most recently raised exceptionit' commonly used in exception handlers to propagate exceptions that have been caught version skew notepython no longer supports the raise excargs form that is still available in python in xuse the raise exc(argsinstance-creation call form described in this book instead the equivalent comma form in is legacy syntax provided for compatibility with the now-defunct string-based exceptions modeland it' deprecated in if usedit is converted to the call form as in earlier releasesa raise exc form is also allowed to name class-it is converted to raise exc(in both versionscalling the class constructor with no arguments besides its defunct comma syntaxpython ' raise also allowed for either string or class exceptionsbut the former is removed in deprecated in and not covered here except for brief mention in the next use classes for new exceptions today raising exceptions to make this clearerlet' look at some examples with built-in exceptionsthe following two forms are equivalent--both raise an instance of the exception class namedbut the first creates the instance implicitlyraise indexerror raise indexerror(class (instance createdinstance (created in statementwe can also create the instance ahead of time--because the raise statement accepts any kind of object referencethe following two examples raise indexerror just like the prior twoexc indexerror(raise exc create instance ahead of time excs [indexerrortypeerrorraise excs[ when an exception is raisedpython sends the raised instance along with the exception if try includes an except name as xclausethe variable will be assigned the instance provided in the raisethe raise statement