from TEMD.temd import TEMD
# Initialize TEMD for global error handling
temd = TEMD()
temd.init() # This sets up the global error handler
print("Global error handling active!")
# Example of automatic error handling
my_list = [1, 2, 3]
print(my_list[5]) # This will raise an IndexError and TEMD will handle it
# Example function that will trigger an IndexError
def forloop():
my_list = [1, 2, 3]
for i in range(5):
print(my_list[i])
# Calling the function will automatically trigger TEMD's global error handler
forloop() # This should trigger an IndexError, and TEMD will explain it
# Focused Error Handling with wrap() (Only this block of code will be monitored)
user_code = """
def forloop():
my_list = [1, 2, 3]
for i in range(5):
print(my_list[i])
forloop()
"""
temd.wrap(user_code) # This will catch errors in the wrapped block and explain them