Skip to content

Commit 0b3734b

Browse files
authored
Merge pull request #94 from braboj/codex/add-descriptive-headers-to-example-files
Add structured headers to exception examples
2 parents 7e8a8fd + a13c774 commit 0b3734b

10 files changed

Lines changed: 39 additions & 6 deletions

examples/14_exceptions/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Exception Example Package
2+
# --------------------------------------------------------------------------------
3+
# Contains modules demonstrating custom exception hierarchies and handling
4+
# patterns.

examples/14_exceptions/demo_generation.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
# Old-Style Exception Generation
2+
# --------------------------------------------------------------------------------
3+
# Shows what happens when raising an exception class that does not inherit from
4+
# BaseException.
5+
16
# class NewStyleException(Exception): pass
27
#
38
# try:

examples/14_exceptions/demo_handlers.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
# Exception Handling Styles
2+
# --------------------------------------------------------------------------------
3+
# Compares using a single except clause against multiple specific handlers for
4+
# related errors.
5+
16
def raise_overflow_error():
27
raise OverflowError
38

examples/14_exceptions/exception_catch_multiple.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
# Example: Catch Multiple Exceptions with junior Single Except Block
1+
# Grouped Exception Handling
2+
# --------------------------------------------------------------------------------
3+
# Illustrates catching different members of an exception hierarchy with one
4+
# except block.
25

36

47
from exception_hierarchy import *

examples/14_exceptions/exception_chaining.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
# Example: Exception Chaining
1+
# Exception Chaining
2+
# --------------------------------------------------------------------------------
3+
# Demonstrates explicit and implicit chaining of exceptions to preserve the
4+
# original error context.
25

36
class MyException(Exception):
47
pass

examples/14_exceptions/exception_files.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# Exception Files Layout
2+
# --------------------------------------------------------------------------------
3+
# Displays a sample directory tree for keeping custom error definitions organized.
4+
15
src/
26
├─ socket
37
│ ├─ __init__.py

examples/14_exceptions/exception_flow_with_try_except.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
# Example: Exception Flow with try-except statements
1+
# Control Flow with try/except
2+
# --------------------------------------------------------------------------------
3+
# Shows normal execution resuming after errors are caught and handled.
24
def func_a(x):
35
# Function uses and returns only positive values
46
if x < 0:

examples/14_exceptions/exception_flow_without_try_except.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
# Example of exception flow without try/except statements
1+
# Control Flow without try/except
2+
# --------------------------------------------------------------------------------
3+
# Illustrates manual error checking when no exception handlers are used.
24

35
def func_a(x):
46
# Function uses and returns only positive values

examples/14_exceptions/exception_handling.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
# Example: Exception Handling with try-except statements
1+
# Structured Exception Handling
2+
# --------------------------------------------------------------------------------
3+
# Uses try/except/else/finally blocks to handle expected and unexpected errors.
24

35
import time
46

examples/14_exceptions/exception_hierarchy.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
# Example: Exception Hierarchy in junior Package
1+
# Custom Exception Hierarchy
2+
# --------------------------------------------------------------------------------
3+
# Defines a family of related custom exceptions and demonstrates raising each
4+
# member of the hierarchy.
25

36
class SocketError(Exception):
47

0 commit comments

Comments
 (0)