Perform a given operation on successful file open and ensure the file is closed afterwards or perform a different operation if the file fails to open.