+ 1

where we can use try catch in java leaving array

I'll be kush if u give example x_x

23rd Jul 2020, 5:41 PM
stoped
stoped - avatar
13 Respuestas
0
Ehm, then your keywords must have been strange, because Arrays are a very rare use case... The most exceptions handled in Java should be all sort of IO-stuff and network issues. Parsing exceptions, all database exceptions, casting exceptions, number and date format exceptions. And the probably (hopefully) biggest part are all kind of exceptions, which are used to handle bad input within the code or from interfaces: Runtime, Nullpointer and all sort of user defined exceptions. Here a sample so you can see, that an exception can be placed anywhere: https://code.sololearn.com/cocuoF2Ta6yc/?ref=app
24th Jul 2020, 2:39 AM
Sandra Meyer
Sandra Meyer - avatar
+ 3
Am really thankful for these explinations,thank you for clearing my doubts🙂
24th Jul 2020, 3:25 AM
stoped
stoped - avatar
+ 1
I would like to give you an answer, but therefore I need to know, what exactly you mean with "leaving array" (??)...
23rd Jul 2020, 8:47 PM
Sandra Meyer
Sandra Meyer - avatar
+ 1
I meant that where ever i searched for this try..catch they were specifically telling for array ,not any explination for other elements
24th Jul 2020, 2:26 AM
stoped
stoped - avatar
+ 1
According to me you said that we can use it in any io,so here can you check this code and correct it with my mistake mentioned https://code.sololearn.com/c1mQeUT0F1kI/?ref=app
24th Jul 2020, 3:12 AM
stoped
stoped - avatar
+ 1
Like what i mean is that it have an error so it must not stop execution of other parts.
24th Jul 2020, 3:15 AM
stoped
stoped - avatar
0
*no guarantee that this list is complete 😉
24th Jul 2020, 2:40 AM
Sandra Meyer
Sandra Meyer - avatar
0
Here I used plain exceptions to handle invalid input: https://code.sololearn.com/c8M9Y10ebKAe/?ref=app
24th Jul 2020, 2:50 AM
Sandra Meyer
Sandra Meyer - avatar
0
Here a number format exception: https://code.sololearn.com/cj9txutZNqAF/?ref=app
24th Jul 2020, 2:51 AM
Sandra Meyer
Sandra Meyer - avatar
0
You can also just fix the little bug in your own code and enter some invalid data as input (e.g. "ABC 3") and you'll have another use case 😉 https://code.sololearn.com/cigIE5GS6M0j/?ref=app
24th Jul 2020, 3:06 AM
Sandra Meyer
Sandra Meyer - avatar
0
You need to put the command, which is causing an exception within the catch block. Here it is not the printing, but the method nextInt() on an input of type string. int b = 0; try { b = sc.nextInt();
24th Jul 2020, 3:18 AM
Sandra Meyer
Sandra Meyer - avatar
0
Btw. if you do as I posted now, you would proceed with your program and cause another exception (division by zero) - but good to train 😁👍
24th Jul 2020, 3:19 AM
Sandra Meyer
Sandra Meyer - avatar
0
There are some errors which require to stop the execution, e.g. it doesn't make any sense to proceed with operations on a database, if there's no connection. You can have exceptions, which you can handle otherwise, e.g. by using default values.
24th Jul 2020, 3:22 AM
Sandra Meyer
Sandra Meyer - avatar