Exception Alias
When you catch an exception (error), you can save information about this exception using the as
keyword.
The full alias structure:
except {error_type} as {variable_name}:
# code block
The alias allows us to display information about caught errors.
Look at the example:
1234567try: a = "string" + 10 except TypeError as error: print("TypeError:", error) print("The following code should be executed:") print("5 + 10 =", 5 + 10)
Var allt tydligt?
Tack för dina kommentarer!
Avsnitt 1. Kapitel 5
Fråga AI
Fråga AI
Fråga vad du vill eller prova någon av de föreslagna frågorna för att starta vårt samtal
Suggested prompts:
Ställ mig frågor om detta ämne
Sammanfatta detta kapitel
Visa verkliga exempel
Awesome!
Completion rate improved to 11.11
Exception Alias
Svep för att visa menyn
When you catch an exception (error), you can save information about this exception using the as
keyword.
The full alias structure:
except {error_type} as {variable_name}:
# code block
The alias allows us to display information about caught errors.
Look at the example:
1234567try: a = "string" + 10 except TypeError as error: print("TypeError:", error) print("The following code should be executed:") print("5 + 10 =", 5 + 10)
Var allt tydligt?
Tack för dina kommentarer!
Avsnitt 1. Kapitel 5