From 00225cd186ca0b96047220ff5a944cd0bc7afe30 Mon Sep 17 00:00:00 2001 From: Ken Nguyen <30739815+kennguyen01@users.noreply.github.com> Date: Sat, 3 Nov 2018 13:32:20 -0400 Subject: [PATCH] Added else and finally clauses example (#20771) --- .../python/exception-and-error-handling/index.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/guide/english/python/exception-and-error-handling/index.md b/guide/english/python/exception-and-error-handling/index.md index 8877667fcd..dac0c105b2 100644 --- a/guide/english/python/exception-and-error-handling/index.md +++ b/guide/english/python/exception-and-error-handling/index.md @@ -29,7 +29,22 @@ except Exception as err: >>> error: >>> must be str, not int ``` +Two additional clauses for the try-except statement are `else` and `finally`. The `else` clause executes when the program runs successfully without any error. While the `finally` clause will always execute no matter what: +```python +try: + print("this is a " + "string") +except Exception as err: + print("error:\n" + str(err)) +else: + print("successfully concatenated string") +finally: + print("end execution") + +>>> this is a string +>>> successfully concatenated string +>>> end execution +``` More Information: Errors and Exceptions documentation.