Make sure resource get cleared on unexpected exception