mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-05-28 18:26:54 +00:00
fix(curriculum): update custom exception example in Python review (#66102)
This commit is contained in:
+3
-3
@@ -99,20 +99,20 @@ dashedName: review-error-handling
|
||||
return f"Welcome, {username}!"
|
||||
```
|
||||
|
||||
Here's a how you can use the `login` function from the `InvalidCredentialsError` exception:
|
||||
Here's a how you can use the `login` function with the `InvalidCredentialsError` exception:
|
||||
|
||||
```py
|
||||
# failed login attempt
|
||||
try:
|
||||
message = login("user", "wrongpassword")
|
||||
print(message)
|
||||
except InvalidCredentialsError as e:
|
||||
print(f"Login failed: {e}")
|
||||
else:
|
||||
print(message)
|
||||
|
||||
# successful login attempt
|
||||
try:
|
||||
message = login("admin", "password123")
|
||||
print(message)
|
||||
except InvalidCredentialsError as e:
|
||||
# This block is not executed because the login was successful
|
||||
print(f"Login failed: {e}")
|
||||
|
||||
@@ -2041,20 +2041,20 @@ if __name__ == '__main__':
|
||||
return f"Welcome, {username}!"
|
||||
```
|
||||
|
||||
Here's a how you can use the `login` function from the `InvalidCredentialsError` exception:
|
||||
Here's a how you can use the `login` function with the `InvalidCredentialsError` exception:
|
||||
|
||||
```py
|
||||
# failed login attempt
|
||||
try:
|
||||
message = login("user", "wrongpassword")
|
||||
print(message)
|
||||
except InvalidCredentialsError as e:
|
||||
print(f"Login failed: {e}")
|
||||
else:
|
||||
print(message)
|
||||
|
||||
# successful login attempt
|
||||
try:
|
||||
message = login("admin", "password123")
|
||||
print(message)
|
||||
except InvalidCredentialsError as e:
|
||||
# This block is not executed because the login was successful
|
||||
print(f"Login failed: {e}")
|
||||
|
||||
Reference in New Issue
Block a user