Skip to content

Commit 7bff42e

Browse files
committed
Exceptions
1 parent a4b7f67 commit 7bff42e

File tree

1 file changed

+31
-31
lines changed

1 file changed

+31
-31
lines changed

README.md

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -798,6 +798,37 @@ LogicOp = Enum('LogicOp', {'AND': partial(lambda l, r: l and r),
798798
```
799799

800800

801+
Exceptions
802+
----------
803+
```python
804+
while True:
805+
try:
806+
x = int(input('Please enter a number: '))
807+
except ValueError:
808+
print('Oops! That was no valid number. Try again...')
809+
else:
810+
print('Thank you.')
811+
break
812+
```
813+
814+
#### Raising exception:
815+
```python
816+
raise ValueError('A very specific message!')
817+
```
818+
819+
### Finally
820+
```python
821+
>>> try:
822+
... raise KeyboardInterrupt
823+
... finally:
824+
... print('Goodbye, world!')
825+
Goodbye, world!
826+
Traceback (most recent call last):
827+
File "<stdin>", line 2, in <module>
828+
KeyboardInterrupt
829+
```
830+
831+
801832
System
802833
------
803834
### Command Line Arguments
@@ -988,37 +1019,6 @@ db.commit()
9881019
```
9891020

9901021

991-
Exceptions
992-
----------
993-
```python
994-
while True:
995-
try:
996-
x = int(input('Please enter a number: '))
997-
except ValueError:
998-
print('Oops! That was no valid number. Try again...')
999-
else:
1000-
print('Thank you.')
1001-
break
1002-
```
1003-
1004-
#### Raising exception:
1005-
```python
1006-
raise ValueError('A very specific message!')
1007-
```
1008-
1009-
### Finally
1010-
```python
1011-
>>> try:
1012-
... raise KeyboardInterrupt
1013-
... finally:
1014-
... print('Goodbye, world!')
1015-
Goodbye, world!
1016-
Traceback (most recent call last):
1017-
File "<stdin>", line 2, in <module>
1018-
KeyboardInterrupt
1019-
```
1020-
1021-
10221022
Bytes
10231023
-----
10241024
**Bytes object is immutable sequence of single bytes. Mutable version is called bytearray.**

0 commit comments

Comments
 (0)