Browse by Topic

Popular

Latest

Latest Posts

An illustration of a Python exception being caught by a handler block that binds it to a named variable for inspection.
Python

Python except as: Clinging to Exception Details

python except as: Learn how the `except ... as ...` clause binds an exception instance in Python, what you can inspect on it, and where the bound variable can and cann...

exception handlingtry exceptPython errorsexception chaining
Illustration of a Python try-except block showing an exception variable being bound and used for logging.
Python

Python Exception Variable: Syntax and Scope

Learn how to use the Python exception variable in try/except blocks, understand its scope and attributes, and see practical logging and error-handling examples.

Exception Handlingtry-exceptError HandlingPython Syntax
Illustration of a Python try/finally block ensuring cleanup code always runs, with a shield representing exception safety.
Python

Python Try Finally: Cleanup That Always Runs

Understand how Python's try/finally guarantees cleanup code runs, how it interacts with exceptions and returns, and when to use it instead of context managers.

try-finallyexception handlingresource cleanupPython control flow
A visual comparison of Python assert and raise statements for error handling.
Python

Python assert vs raise: Key Differences

Learn the difference between Python's assert and raise statements, when each one fits, and why assert checks are disabled by optimization flags.

assertraiseexception handlingpython debugging
Illustration of a Python assert statement with a checkmark and a warning sign, representing validation and debugging.
Python

Python Assert Statement: Syntax, Usage, and Pitfalls

The Python assert statement: Learn how it works, when to use it for debugging, and why it should not replace input validation.

pythonassertionsdebuggingerror handling
Illustration of a Python custom exception class with attributes and error handling context.
Python

Python Custom Exception Class: Definition and Usage

Learn how to define a Python custom exception class, add context attributes, handle errors cleanly, and follow maintainability best practices.

python exceptionserror handlingcustom exceptionsexception classes
A Python code editor showing a custom exception class definition with a raise statement, illustrating user defined exceptions.
Python

Python User Defined Exception: Custom Error Handling

Learn how to create a Python user defined exception with attributes, raise it, handle it, and design a maintainable exception hierarchy.

custom exceptionserror handlingexception hierarchypython classes
Custom exception class diagram showing a Python exception hierarchy with a custom error class
Python

How to Define and Use Custom Exceptions in Python

Learn how to define custom exceptions in Python, add context, and use them for clearer, more maintainable error handling.

pythonexceptionserror-handlingcustom-ex-exceptions
Diagram showing an exception chained to its cause in a Python traceback.
Python

Python Exception Chaining: How to Preserve the Root Cause

python exception chaining: Learn how Python exception chaining preserves the original error when a new exception is raised, using `raise ... from` and `__cause__` to k...

exception chainingraise fromtracebackerror handling
Illustration of a Python exception chaining to its root cause with the raise from syntax
Python

Python raise from: Chaining Exceptions Clearly

Learn how Python's raise ... from ... syntax chains exceptions explicitly, preserves the original cause in tracebacks, and when to use from None.

exception chainingtracebackerror handlingpython exceptions