+ 3
Exception Java
How do you choose between try/catch or Throws ?
23 Answers
+ 3
ok many thanks š
+ 2
thanks for your answer š so if I well understand you choose try/catch when you are sure exception will occur
+ 2
Hi
+ 2
Hlo
+ 1
I choose try/catch when I am not shure what exactly will happen. For example everything outside my program like user input, load/save files, connection to database or a server....
You can always read the docomentation (java doc or whatever libary u r using) to check what exceptions can occure.
+ 1
Please come in chat
+ 1
hi
+ 1
Update app. In notifications there will be mesaages. In that mesaage me
+ 1
many thanks š
+ 1
pourquoi se venger ??? sur qui?
+ 1
it was for Java chalenges. I've lost against somebody yesterday
+ 1
Thanks Very clear explanations !!!
+ 1
You use try when something may go wrong later, for example, using a audio file from external source, like this :
https://code.sololearn.com/Wl23AIEG6SuZ/?ref=app
Because the website may break down, or they remove the mp3 files. We use try-catch when loading the audio, and don't forget to use try-catch when trying the audio too (line 114 and 123).
throw is similar to assertion, for example, a program only for 18 years old or above, and the user entered that his age is 16, now you can use throw to raise an error to terminate the program and give the user a warning.
+ 1
Many thanks for explanations š
0
Use try/catch to handle existing exceptions.
And use throws to generate a new exception.
0
Nice!
0
Try catch is used when you want to catch and handle the exception.
Throws is used to propagate the exception to the caller of the method then the caller will handle that exception..
0
Je prendrais ma revenge
0
Supergirl no problem ;) keep up learning šŖ
0
Meko batao yaar ek ans