Log, Then Re-raise Unchanged

Medium ⏱ 12 min 55% acceptance ★★★★☆ 4.4
Write audited(func, log) that calls the zero-argument func() and returns its result; if it raises, append the string type(err).__name__ to the log list and re-raise the same exception with a bare raise (preserving the original traceback — not raise err).

Examples

Example 1
Input
audited(lambda: 1 / 0, log)
Output
ZeroDivisionError propagates; log == ['ZeroDivisionError']
Explanation

The error is recorded but not altered.

Constraints

  • Use bare raise, not raise err.
  • Log the class name, not the message.

Topics

Exception Handlingbare raise

Companies

DatadogSplunkCisco

Hints

Hint 1

except Exception as err: log.append(...); raise.

Hint 2

Bare raise keeps the original traceback intact.

Loading the Python runtime… Run executes your code and shows printed output; Submit checks your function against this problem's examples.