haven't tried it yet and thought i'd ask in case a...
# cfml-general
w
haven't tried it yet and thought i'd ask in case anyone already tried, but what happens in a try/catch/finally if you rethrow the exception in the catch? will the finally code execute or be skipped? assuming skipped, but again haven't actually tried
b
Finally always runs.
w
in the scenario above, WHEN would it run, before the rethrow, after, or 'simultaneously'?
b
In fact, I'll often do this when I just need it for cleanup
Copy code
var jFile = someJavaFileThatNeedsClosed();
try {
  jFile.doSomethingThatMayError();
} finally {
  jFile.close();
}
w
let me create an example on trycf, sec
b
WHEN would it run
after your catch runs, but before the actual exception is re-raised
w
run this, then run it again uncommenting the rethrow: https://trycf.com/gist/166d8f3b30cab4794ba61ac81fa38c47/lucee5?theme=monokai
b
Why are you telling me to run it, I'm the one who already knows how it works 🙂
And, you'll note, your code example proves what I already told you above 😉
except you have to wrap another catch to actually see it, lol
trycf doesn't flush your writeoutputs
w
i see it now
b
☝️ This shows better
w
so it executes before the rethrow
b
Correct
Also, any code after your rethrow in the catch won't run regardless just like any throw
w
of course. thanks