Skip to content

Commit 66cb4de

Browse files
author
Arie Bregman
authored
Merge pull request iluwatar#63 from sagorbrur/patch-2
added answer under Python/Explain Exception....
2 parents b91df41 + ee1870b commit 66cb4de

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3230,6 +3230,29 @@ Generally, every compiling process have a two steps.
32303230

32313231
<details>
32323232
<summary>Explain Exception Handling and how to use it in Python</summary><br><b>
3233+
3234+
**Exceptions:** Errors detected during execution are called Exceptions.
3235+
3236+
**Handling Exception:** When an error occurs, or exception as we call it, Python will normally stop and generate an error message.</br>
3237+
Exceptions can be handled using `try` and `except` statement in python.
3238+
3239+
**Example:** Following example asks the user for input until a valid integer has been entered. </br>
3240+
If user enter a non-integer value it will raise exception and using except it will catch that exception and ask the user to enter valid integer again.
3241+
3242+
3243+
```py
3244+
while True:
3245+
try:
3246+
a = int(input("please enter an integer value: "))
3247+
print(a)
3248+
break
3249+
except:
3250+
print("Ops! Please enter a valid integer value.")
3251+
3252+
```
3253+
3254+
For more details about errors and exceptions follow this [https://docs.python.org/3/tutorial/errors.html](https://docs.python.org/3/tutorial/errors.html)
3255+
32333256
</b></details>
32343257

32353258
<details>

0 commit comments

Comments
 (0)