Skip to content

Latest commit

 

History

History
22 lines (16 loc) · 1.19 KB

vi.f.3-finally-handlers-still-guaranteed-once-a-try-block-is-entered.md

File metadata and controls

22 lines (16 loc) · 1.19 KB

VI.F.3 Finally handlers still guaranteed once a try block is entered

Because relaxed sequences cannot span across protected non-trivial region boundaries, this guarantee still holds. This is essential for preserving the usual idiom for acquiring and releasing a resource:

[Example:

bool acquired = false;
try {
    acquire(ref acquired);
    S1;
}
finally {
    if (acquired) release resource;
}

end example]

Quite often, the programmer knows little about how S1 might fail. If the "acquire", S1, and "release" were allowed to be part of the same relaxed sequence, and S1 failed, then the acquire and/or release portions could be suppressed at whim (by the rest of the rules). By forcing the three parts to be in three separate sequences, we eliminate problems with regard to S1 failing. Of course, we do not eliminate problems that might arise if something else in the sequence for "acquire" fails, but that is a problem that can't be dealt with at the CLI level, and must be left to the programmer.

Relaxed sequences are allowed to span trivial region boundaries because optimizers were already allowed to remove such regions even when strict exception handling is specified.