Browse Source

Exceptions

pull/10/head
Jure Šorn 6 years ago
parent
commit
7bff42e0d7
1 changed files with 31 additions and 31 deletions
  1. 62
      README.md

62
README.md

@ -798,6 +798,37 @@ LogicOp = Enum('LogicOp', {'AND': partial(lambda l, r: l and r),
``` ```
Exceptions
----------
```python
while True:
try:
x = int(input('Please enter a number: '))
except ValueError:
print('Oops! That was no valid number. Try again...')
else:
print('Thank you.')
break
```
#### Raising exception:
```python
raise ValueError('A very specific message!')
```
### Finally
```python
>>> try:
... raise KeyboardInterrupt
... finally:
... print('Goodbye, world!')
Goodbye, world!
Traceback (most recent call last):
File "<stdin>", line 2, in <module>
KeyboardInterrupt
```
System System
------ ------
### Command Line Arguments ### Command Line Arguments
@ -988,37 +1019,6 @@ db.commit()
``` ```
Exceptions
----------
```python
while True:
try:
x = int(input('Please enter a number: '))
except ValueError:
print('Oops! That was no valid number. Try again...')
else:
print('Thank you.')
break
```
#### Raising exception:
```python
raise ValueError('A very specific message!')
```
### Finally
```python
>>> try:
... raise KeyboardInterrupt
... finally:
... print('Goodbye, world!')
Goodbye, world!
Traceback (most recent call last):
File "<stdin>", line 2, in <module>
KeyboardInterrupt
```
Bytes Bytes
----- -----
**Bytes object is immutable sequence of single bytes. Mutable version is called bytearray.** **Bytes object is immutable sequence of single bytes. Mutable version is called bytearray.**

Loading…
Cancel
Save