I am trying to understand try-catch block. Mostly, I got the point but there are two points, which I did not understand and do not know with which terms should I search them.
try{
operation1;
operation2;
operation3;
operation4;
}catch(Exception e){
//exception handling here.
}
Q1: For example, in an example like on the above. If the operation1
and operation2
are completed successfully but during the operation3
, if it throws an exception, Will operation1
and operation2
be undone? or will they stay with the values after operations?
Q2. In case I do not know, which exceptions may my operations throw. What would be the best approach to this? As far as I know, throwing simply Exception
is not a good practice.