0

What is the use of try: ? It makes the program too complex ... We cant use try n expect every time !

14th Aug 2016, 3:00 PM
Harish Krishna
Harish Krishna  - avatar
6 Réponses
+ 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
15th Aug 2016, 5:06 AM
Saeed Mohagheghi
Saeed Mohagheghi - avatar
+ 2
this is for unexepted errors. and you should use it.
14th Aug 2016, 3:15 PM
nima sadeghpour
+ 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.
20th Aug 2016, 5:04 PM
Biswajit Samal
Biswajit Samal - avatar
+ 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
27th Aug 2016, 10:18 AM
Giovanni Gatto
Giovanni Gatto - avatar
+ 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.
31st Aug 2016, 2:50 AM
Cesar Lopez
Cesar Lopez - avatar
- 1
if we use try n expect in program it will never terminate program if some unexpected error occor.
15th Aug 2016, 9:33 AM
Bharati Deepak Giri