Chaining Custom Exceptions

Mon 10 August 2026
class InitialError(Exception):
    pass

class DerivedError(Exception):
    pass

try:
    try:
        raise InitialError("Initial failure")
    except InitialError as e:
        raise DerivedError("Follow-up failure") from e
except DerivedError as final_error:
    print(final_error)
Follow-up failure


Score: 10

Category: chapter7_custom_exceptions

Read More

Changing The Working Directory

Mon 10 August 2026
import os

os.chdir("C:/Projects")
print(os.getcwd())
---------------------------------------------------------------------------

FileNotFoundError                         Traceback (most recent call last)

Cell In[1], line 3
      1 import os
----> 3 os.chdir("C:/Projects")
      4 print(os.getcwd())


FileNotFoundError: [WinError 2] The system cannot find the file specified: 'C:/Projects'


Score: 10

Category: chapter12_file_handling

Read More
Page 3 of 20

« Prev Next »