From 7bff42e0d7c0b86f54767b135134264a38cc7ad5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=A0orn?= Date: Wed, 30 Jan 2019 11:19:12 +0100 Subject: [PATCH] Exceptions --- README.md | 62 +++++++++++++++++++++++++++---------------------------- 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/README.md b/README.md index 0667c85..04bd6bf 100644 --- a/README.md +++ b/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 "", line 2, in +KeyboardInterrupt +``` + + System ------ ### 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 "", line 2, in -KeyboardInterrupt -``` - - Bytes ----- **Bytes object is immutable sequence of single bytes. Mutable version is called bytearray.**