Skip to content

Commit 99b5eb1

Browse files
authored
Merge pull request #473 from techboy-coder/patch-1
Fix errors in exception-handling.md
2 parents 490b0c9 + 453ba97 commit 99b5eb1

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

docs/cheatsheet/exception-handling.md

+11-6
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ You can't divide by zero, that is a mathematical true, and if you try to do it i
2727
... print(dividend / divisor)
2828
...
2929
>>> divide(dividend=10, divisor=5)
30-
# 5
30+
# 2
3131

3232
>>> divide(dividend=10, divisor=0)
3333
# Traceback (most recent call last):
@@ -45,7 +45,7 @@ Let's say we don't want our program to stop its execution or show the user an ou
4545
... print('You can not divide by 0')
4646
...
4747
>>> divide(dividend=10, divisor=5)
48-
# 5
48+
# 2
4949

5050
>>> divide(dividend=10, divisor=0)
5151
# You can not divide by 0
@@ -58,17 +58,22 @@ You can also handle multiple exceptions in one line like the following without t
5858
```python
5959
>>> def divide(dividend , divisor):
6060
... try:
61-
... var = 'str' + 1
62-
... print(dividend / divisor)
61+
... if (dividend == 10):
62+
... var = 'str' + 1
63+
... else:
64+
... print(dividend / divisor)
6365
... except (ZeroDivisionError, TypeError) as error:
6466
... print(error)
6567
...
68+
69+
>>> divide(dividend=20, divisor=5)
70+
# 4
71+
6672
>>> divide(dividend=10, divisor=5)
67-
# 5
73+
# `can only concatenate str (not "int") to str` Error message
6874

6975
>>> divide(dividend=10, divisor=0)
7076
# `division by zero` Error message
71-
# `can only concatenate str (not "int") to str` Error message
7277
```
7378

7479
## Finally code in exception handling

0 commit comments

Comments
 (0)