0
When should I use a new block of try statement?
Because I am a little bit confusing...
2 Antworten
+ 1
When you think that there is something in the program, it may give the exception, for example, that the user enters a value of the integer type and is required to enter a value of the type String.
So you do a try block to avoid the error and the program keeps running, meaning it does not stop.
+ 2
If your program has possibility to contain more than one exceptions. Than you have to Cath multiple exceptions. If don't want do this, than Catch all the exceptions.
I.e .1
try{
}catch(IOException e){
//Catches single exception
}
I.e.2
//Catches both exception
try{
}catch(IOException e){
}catch(NullpointerExeption e){
}
I.e.3 try{
}catch(Exception e){
//Catches all the exception
}