Rethrow Loses Stack Trace (ARCH2154)
Esta página aún no está disponible en tu idioma.
Key python.logging.raise-without-from · Severity info · Category logging
Calling raise NewError() inside a handler without from e drops the original exception’s stack trace and cause. This hides the true source of the error and makes debugging harder.
Incorrect
Section titled “Incorrect”try: config = json.loads(raw)except ValueError: raise ConfigError("Invalid configuration")Correct
Section titled “Correct”try: config = json.loads(raw)except ValueError as e: raise ConfigError("Invalid configuration") from eRaise the new exception with raise ... from e to preserve the original cause and stack trace.