Of course!
So, the rule number one: if I just want to do some cleanup (close files/dirs, deallocate things and so on), I simply put defer
right after each operation that needs cleanup given that I acquire a resource with try getSomeThing()
. Did I get you right (regarding first part of the answer)?