Were actions taken to refuse to handle exceptions before the exception occurred?

Imagine I have such a method

void myMethod(MyThing t) throws MyException {
   t.foo = "bar";
   if (t.condition()) { 
      throw new MyException();
   }
}

If an exception is thrown, does the value of t.foo revert to what it was before? Or does it save the value of "bar"?

+5
source share
4 answers

The value of the foo property on your MyThing object will not be returned to any exception.

There is no block in your example try, but if it is, you can perform your own type of value rollback in the corresponding block catch.

try {
    t.foo = "bar";
    doSomethingRiskyWhichMightThrowMyException();
} catch(MyException e) {
    t.foo = "rolledbackvalue";
}
+8
source

Throwing / catching Exceptions do not automatically imply any kind of rollback operation.

foo , , .

+3

. , catch. , catch. , , . , , - .

+3

. First .. ( goto ). , , Java ( try-catch) , , . , "" t.foo. "bar". , .

+2

All Articles