+ 2

try....catch

In java script I didn't understand try....catch. Can anyone explain it with examples?

10th Apr 2020, 12:07 PM
Shadman Sakib
Shadman Sakib - avatar
7 Respuestas
+ 2
You may find answer in https://javascript.info/try-catch
10th Apr 2020, 1:48 PM
narayanaprasad
narayanaprasad - avatar
+ 1
I said in javascript not java
10th Apr 2020, 12:48 PM
Shadman Sakib
Shadman Sakib - avatar
+ 1
ok
10th Apr 2020, 12:51 PM
Shadman Sakib
Shadman Sakib - avatar
+ 1
I couldn't understand the logic 😅 can you explain?
10th Apr 2020, 12:53 PM
Shadman Sakib
Shadman Sakib - avatar
+ 1
As you know it gives an error when you try dividing number with 0. When this occurs, program brokes. So if you type your code inside try block, program does not stop running, instead it handles the error and throws an exception. For another example if you create string variable, and take an input, if user enters numerical value, program also brokes. Because, string str != 227 (some numerical value) To handle this too, you type your code inside try block, so your program does not stop running, but notifies user because something went wrong.
10th Apr 2020, 1:06 PM
Mustafa K.
Mustafa K. - avatar
0
https://www.sololearn.com/Discuss/1523730/?ref=app Please next time use search bar for your question before asking.
10th Apr 2020, 12:47 PM
Mustafa K.
Mustafa K. - avatar
0
Its logic is same, does not matter which language you use.
10th Apr 2020, 12:49 PM
Mustafa K.
Mustafa K. - avatar