From c0781a97c62889d5396dbbb59e53dd396d8053e0 Mon Sep 17 00:00:00 2001 From: Lazar Gugleta Date: Fri, 11 Oct 2019 23:26:36 +0200 Subject: [PATCH] add snippet try else --- snippets/try_else.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 snippets/try_else.md diff --git a/snippets/try_else.md b/snippets/try_else.md new file mode 100644 index 000000000..444fb556c --- /dev/null +++ b/snippets/try_else.md @@ -0,0 +1,18 @@ +--- +title: Try else +tags: utility,intermediate +--- + +Rises an `exception` if it is caught in the `try` block. + +You can have an else clause as part of a `try/except` block, which is executed if no `exception` is thrown. + +```py +try: + 5*6 +except TypeError: + print("An exception was raised") +else: + print("No exceptions were raised.") +``` +