0
What is the use of try: ? It makes the program too complex ... We cant use try n expect every time !
6 Antworten
+ 5
a good example is when a user should input special entry and you don't know if the input is in right format and type or not! so one good way is handling unknown unexpected entries with try
+ 2
this is for unexepted errors. and you should use it.
+ 1
basically we use this to Handel any unexpected error during the execution of program. we give a very proper and readable error message to user to understand it clearly and better debugging.
+ 1
use it when you ask an input and you need it to be an int for example, so, if the user inputs a letter you can handle it, print a message that advices the user to input a number instead of a letter and avoid the program to end with an error that the user does not understand
+ 1
you should always write your programs defensively. you should use try/except when there is something that you can't control by yourself, for instance when writing data to disk, reading content from internet, etc.
- 1
if we use try n expect in program it will never terminate program if some unexpected error occor.