From 5b64670682b7da3e2adbba13463ae565fdd7bb49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=A0orn?= Date: Fri, 29 Jul 2022 03:11:24 +0200 Subject: [PATCH] Exceptions --- README.md | 10 +++++----- index.html | 14 +++++++------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index f2c85e3..96ea90b 100644 --- a/README.md +++ b/README.md @@ -1371,7 +1371,6 @@ LogicOp = Enum('LogicOp', {'AND': partial(lambda l, r: l and r), Exceptions ---------- -### Basic Example ```python try: @@ -1397,14 +1396,15 @@ finally: ### Catching Exceptions ```python -except : -except as : -except (, [...]): -except (, [...]) as : +except : ... +except as : ... +except (, [...]): ... +except (, [...]) as : ... ``` * **Also catches subclasses of the exception.** * **Use `'traceback.print_exc()'` to print the error message to stderr.** * **Use `'print()'` to print just the cause of the exception (its arguments).** +* **Use `'logging.exception()'` to log the exception.** ### Raising Exceptions ```python diff --git a/index.html b/index.html index 804dc10..5d712e6 100644 --- a/index.html +++ b/index.html @@ -1176,12 +1176,11 @@ LogicOp = Enum('LogicOp', {#Exceptions

Basic Example

try:
+

#Exceptions

try:
     <code>
 except <exception>:
     <code>
-
- +

Complex Example

try:
     <code_1>
@@ -1199,16 +1198,17 @@ LogicOp = Enum('LogicOp', {'else' block will only be executed if 'try' block had no exceptions.
 
  • Code inside the 'finally' block will always be executed (unless a signal is received).
  • -

    Catching Exceptions

    except <exception>:
    -except <exception> as <name>:
    -except (<exception>, [...]):
    -except (<exception>, [...]) as <name>:
    +

    Catching Exceptions

    except <exception>: ...
    +except <exception> as <name>: ...
    +except (<exception>, [...]): ...
    +except (<exception>, [...]) as <name>: ...
     
    • Also catches subclasses of the exception.
    • Use 'traceback.print_exc()' to print the error message to stderr.
    • Use 'print(<name>)' to print just the cause of the exception (its arguments).
    • +
    • Use 'logging.exception(<message>)' to log the exception.

    Raising Exceptions

    raise <exception>
     raise <exception>()