The Python Language Reference, Release 3.9.5 7.8 The raise statement raise_stmt ::= "raise" [ expression ["from" expression ]] If no expressions are present, raise re-raises the last exception that was active in the current scope. If no exception is active in the current scope, a RuntimeError exception is raised indicating that this is an error. Otherwise, raise evaluates the first expression as the exception object. It must be either a subclass or an instance of$_{BaseException}$ . If it is a class, the exception instance will be obtained when needed by instantiating the class with no arguments. The type of the exception is the exception instance’s class, the value is the instance itself. A traceback object is normally created automatically when an exception is raised and attached to it as the __traceback__ attribute, which is writable. You can create an exception and set your own traceback in one step using the$_{with_traceback()}$ exception method (which returns the same exception instance, with its trace- back set to its argument), like so: raise Exception("foo occurred").with_traceback(tracebackobj) The $_{from}$clause is used for exception chaining: if given, the second expression must be another exception class or instance. If the second expression is an exception instance, it will be attached to the raised exception as the __cause__ attribute (which is writable). If the expression is an exception class, the class will be instantiated and the resulting exception instance will be attached to the raised exception as the$_{__cause__}$ attribute. If the raised exception is not handled, both exceptions will be printed: >>> try : ... print(1/0) ... except Exception as exc: ... raise RuntimeError("Something bad happened") from exc ... Traceback (most recent call last): File "<stdin>" , line2, in <module> ZeroDivisionError : division by zero The above exception was the direct cause of the following exception: Traceback (most recent call last): File "<stdin>" , line4, in <module> RuntimeError: Something bad happened >>> try : ... print(1/0) ... except : ... raise RuntimeError("Something bad happened") ... Traceback (most recent call last): File "<stdin>" , line2, in <module> ZeroDivisionError : division by zero During handling of the above exception, another exception occurred: Traceback (most recent call last): File "<stdin>" , line4, in <module> RuntimeError: Something bad happened A similar mechanism works implicitly if an exception is raised inside an exception handler or a$_{finally}$clause: the previous exception is then attached as the new exception’s$_{__context__}$ attribute: Exception chaining can be explicitly suppressed by specifying$_{None}$ in the$_{from}$clause: 89 7.8. The$_{raise}$ statement