Build systems that stay dependable under stress
Code running in production must handle exceptions appropriately. Uncaught exceptions are a major source of service failures. If an error occurs, handle it gracefully or let it propagate with proper context to a higher-level handler.
Create custom exception classes when built-in exceptions are not sufficient. Inherit from appropriate base exceptions and consider using exception chaining with ‘raise from’ for better error context.
When re-raising exceptions or raising new exceptions due to another exception, use ‘raise NewException() from original_exception’ to preserve the original traceback and provide better debugging context.