File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ # Exception Example Package
2+ # --------------------------------------------------------------------------------
3+ # Contains modules demonstrating custom exception hierarchies and handling
4+ # patterns.
Original file line number Diff line number Diff line change 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:
Original file line number Diff line number Diff line change 1+ # Exception Handling Styles
2+ # --------------------------------------------------------------------------------
3+ # Compares using a single except clause against multiple specific handlers for
4+ # related errors.
5+
16def raise_overflow_error ():
27 raise OverflowError
38
Original file line number Diff line number Diff line change 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
47from exception_hierarchy import *
Original file line number Diff line number Diff line change 1- # Example: Exception Chaining
1+ # Exception Chaining
2+ # --------------------------------------------------------------------------------
3+ # Demonstrates explicit and implicit chaining of exceptions to preserve the
4+ # original error context.
25
36class MyException (Exception ):
47 pass
Original file line number Diff line number Diff line change 1+ # Exception Files Layout
2+ # --------------------------------------------------------------------------------
3+ # Displays a sample directory tree for keeping custom error definitions organized.
4+
15src/
26 ├─ socket
37 │ ├─ __init__.py
Original file line number Diff line number Diff line change 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.
24def func_a (x ):
35 # Function uses and returns only positive values
46 if x < 0 :
Original file line number Diff line number Diff line change 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
35def func_a (x ):
46 # Function uses and returns only positive values
Original file line number Diff line number Diff line change 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
35import time
46
Original file line number Diff line number Diff line change 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
36class SocketError (Exception ):
47
You can’t perform that action at this time.
0 commit comments