From 3031badc280b3fc27bd90107979152722b3d1167 Mon Sep 17 00:00:00 2001 From: chenyanpanHW Date: Sun, 27 Sep 2020 16:20:30 +0800 Subject: [PATCH 1/4] add hello.py. --- patch-tracking/hello.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 patch-tracking/hello.py diff --git a/patch-tracking/hello.py b/patch-tracking/hello.py new file mode 100644 index 00000000..11d1b9a1 --- /dev/null +++ b/patch-tracking/hello.py @@ -0,0 +1,13 @@ +""" hello """ + +if __name__ == "__main__": + try: + s = input('please enter two numbers separated by comma: ') + num1 = int(s.split(',')[0].strip()) + num2 = int(s.split(',')[1].strip()) + except ValueError as err: + print('Value Error: {}'.format(err)) + except IndexError as err: + print('Index Error: {}'.format(err)) + except Exception as err: + print('Other error: {}'.format(err)) -- Gitee From 6c4c961d20aa9fcea3dc6dc9ac8de264d66039cd Mon Sep 17 00:00:00 2001 From: chenyanpan Date: Sun, 27 Sep 2020 16:53:21 +0800 Subject: [PATCH 2/4] raise in Exception --- patch-tracking/hello.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/patch-tracking/hello.py b/patch-tracking/hello.py index 11d1b9a1..29745672 100644 --- a/patch-tracking/hello.py +++ b/patch-tracking/hello.py @@ -1,13 +1,13 @@ """ hello """ -if __name__ == "__main__": - try: - s = input('please enter two numbers separated by comma: ') - num1 = int(s.split(',')[0].strip()) - num2 = int(s.split(',')[1].strip()) - except ValueError as err: - print('Value Error: {}'.format(err)) - except IndexError as err: - print('Index Error: {}'.format(err)) - except Exception as err: - print('Other error: {}'.format(err)) +try: + f = open('myfile.txt') + s = f.readline() + i = int(s.strip()) +except OSError as err: + print("OS error: {0}".format(err)) +except ValueError: + print("Could not convert data to an integer.") +except Exception as err: + print("Unexpected error: %v", err) + raise -- Gitee From 28d78f2e335e51ceb34c51cf157b9711fcdb04f7 Mon Sep 17 00:00:00 2001 From: chenyanpan Date: Sun, 27 Sep 2020 16:54:55 +0800 Subject: [PATCH 3/4] delete as err --- patch-tracking/hello.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/patch-tracking/hello.py b/patch-tracking/hello.py index 29745672..530ba05f 100644 --- a/patch-tracking/hello.py +++ b/patch-tracking/hello.py @@ -8,6 +8,6 @@ except OSError as err: print("OS error: {0}".format(err)) except ValueError: print("Could not convert data to an integer.") -except Exception as err: - print("Unexpected error: %v", err) +except Exception: + print("Unexpected error") raise -- Gitee From 3af3ee938cd2079e0a7b69f8b2de0e911f775865 Mon Sep 17 00:00:00 2001 From: chenyanpan Date: Sun, 27 Sep 2020 16:57:47 +0800 Subject: [PATCH 4/4] raise err --- patch-tracking/hello.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/patch-tracking/hello.py b/patch-tracking/hello.py index 530ba05f..dfebb097 100644 --- a/patch-tracking/hello.py +++ b/patch-tracking/hello.py @@ -8,6 +8,6 @@ except OSError as err: print("OS error: {0}".format(err)) except ValueError: print("Could not convert data to an integer.") -except Exception: - print("Unexpected error") - raise +except Exception as err: + print("Unexpected error: %v", err) + raise err -- Gitee