Is there any way to simulate a try-finally
or try-except
in a language that doesn't have them?
If there's some random, unpredictable, exception happens i need to be sure some cleanup runs.
i could try to be sure that no exception in thrown, that way i am sure my cleanup code always runs - but then i wouldn't need the try-finally/except
.
Right this moment i'm trying to create a try-finally
in Lua; but i think any solution would work in other languages as well.
Although, for the life of me, i cannot figure out how an exception can be handled without the plumbing provided by the language infrastructure.
But never hurts to ask.